Categories
Software Development Technology

AntiXSS Library

During the dinner presentation to Oklahoma City Developer's Group this past Monday (4/5/2010), the topic of input validation was brought up and I recommended the Microsoft AntiXss library to assist with this task. As it turns out, there seems to be an even tighter way to integrate this library into your projects:

http://haacked.com/archive/2010/04/06/using-antixss-as-the-default-encoder-for-asp-net.aspx

Haacked.com presents a great way to integrate the AntiXss library as the default encoder for ASP.NET 4 automatic code block encoding; definitely worth checking out.

Categories
Software Development Technology

Synchronizing AJAX and ASP.NET (OKCDG Presentation)

This is a follow-up to my presentation at the Oklahoma City Developer's Group meetings. I really enjoyed giving this talk and really appreciate the opportunity! I received a lot of great feedback and look forward to any other comments anybody has (feel free to add your 2¢ in the comments below).

 As promised I've attached my slide deck to this post and I will have my code samples up asap so stay tuned for those.

Synchronizing AJAX and ASP.NET.zip (132.48 kb)

Categories
Software Development Technology

jQueryUI vs. Visual Studio jQuery IntelliSense Pt. 2

I thought I would elaborate

on my previous post on the jQueryUI breaking the Visual Studio 2008 Intellisense -vsdoc.js file. This is a quick overview of the two changes necessary to correct the problem. The file breaks in two locations line 165 & line 5815 (Visual Studio indicates these errors as being on lies 164 & 5814). Two quick changes:

Line 165 from this:

selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;

to this:

try {
    selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
}
catch (ex) {
}

And line 5815 from this:

elem = jQuery.makeArray( div.childNodes );

to this:

elem = jQuery.makeArray( div.childNodes );
try {
    elem = jQuery.makeArray( div.childNodes );
}
catch (ex) {
}

That should take care of the issue.

One further note, the jquery-1.4.1-vsdoc.js file will work with the updated jQuery 1.4.2 library, just change the file name to jquery-1.4.2-vsdoc.js.

 

Categories
Software Development Technology

jQueryUI vs. Visual Studio jQuery IntelliSense

I stumbled upon an issue with jQuery IntelliSense in Visual Studio 2008. Basically, the jQuery library (i.e. jquery-1.4.2.min.js) & it's Visual Studio IntelliSense document (i.e. jquery-1.4.2.min-vsdoc.js) play nicely, but when a reference to the jQueryUI library (e.g. jquery-ui-1.8.custom.min.js) is added, the whole thing becomes hung-chowed. To make a long story short, I've made a couple of modifications to the Visual Studio Intellisense document & everyone on the playground is happy again. The updated file is available below:

jquery-1.4.2.min-vsdoc.js (229.42 kb)

If this helped you or if you have any suggestions for improvements, let me know in the comments!

Categories
Software Development Technology

The Simple Solution to List.Find()

Today at work, it was necessary to code a solution that included a List.Find() that I've coded many times and has become almost second nature . . . in C#. However, the app, being written in VB, required a solution in VB. After some searching on the web, I was left without a satisfactory solution. After several (read: many) rounds of trial and error, I finally stumbled upon the correct syntax. Later this afternoon it occurred to me that this would make an excellent inaugural blog post.

In C#, the code is very simple (examples can be found on MSDN). Assuming we have an object named Person that has a property named FirstName of type string:

string strPersonToFind = "Justin";
Person myPerson = People.Find(
    delegate (Person p)
    {
        return p.FirstName == strPersonToFind;
    });

In VB, the examples were far less clean:

Dim strPersonToFind As string = "Justin"
Sub doSomething(ByVal People As List(Of Person))
    Person myPerson = People.Find(addressof FindPerson)
End Sub
Function FindPerson(ByVal s As string) As Boolean
    If s = strPersonToFind Then
        Return True
    Else
        Return False
    End If
End Function

Seriously? The VB example has several obvious shortcomings. First, it requires a page-scoped variable for comparison or a hard-coded comparator. Second, it took 11 lines of code to accomplish what was done in C# in 3. Third, it's just plain ugly; it requires jumping between Subs & Functions and is pretty hard to follow and maintain.

The solution is very simple, looks similar to the C# example, and can be used from within a single Sub or Function (eliminating the need for page-scoped variables):

Dim strPersonToFind As string = "Justin"
Person myPerson = People.Find(Function(ByVal p As Person) p.FirstName = strPersonToFind)

Only two lines of code and very clear and concise syntax.

Important Notes: This is in reference to System.Collections.Generic.List<T> (C#) and System.Collections.Generic.List(Of T) (VB). Also, I believe this known as Lambda Expression syntax and as such, only works .NET 3.5 and higher.

If this helped you, let me know in the comments!