Thursday, March 22, 2012

Server.HtmlEncode(createText.Text) vs. HttpUtility.HtmlEncode(createText.Text);

What is the difference? and which one should I use?

Server.HtmlEncode(createText.Text)

vs.

HttpUtility.HtmlEncode(createText.Text)

Server.HtmlEncode calls HttpUtility.HtmlEncode.


According toReflector, Server is an instance ofHttpServerUtility

Public ReadOnly Property Server As HttpServerUtility
Get
If (Me._server Is Nothing) Then
Me._server = New HttpServerUtility(Me)
End If
Return Me._server
End Get
End Property

And as noted HttpServerUtility.HtmlEncode makes a straight call to the shared method HttpUtility.HtmlEncode

Public Sub HtmlEncode(ByVal s As String, ByVal output As TextWriter)
HttpUtility.HtmlEncode(s, output)
End Sub

So for best performance, you could call directly to HttpUtility.HtmlEncode yourself.

0 comments:

Post a Comment