Showing posts with label createtexttext. Show all posts
Showing posts with label createtexttext. Show all posts

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.

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

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

From thedocumentation:

Server.HtmlEncode is a convenient way to access theSystem.Web.HttpUtility.HtmlEncode method at run time from an ASP.NET Web application. Internally,HtmlEncode usesSystem.Web.HttpUtility.HtmlEncode to encode strings.