ASP.NET C# Html Encoding/Decoding in combination with QueryStrings


I bumped into some issues today concerning with html encoding in querystrings combined with special characters…

Original url: http://yoursharepoint/_layouts/projectx/viewdetail.aspx?ItemID=5&DataPath=RootNode/level1/cliënt
QueryString – “DataPath”= “RootNode/Level1/cliënt” (NOT OK)

I used the method html.Encode() en still the problem occur

Original url: http://yoursharepoint/_layouts/projectx/viewdetail.aspx?ItemID=5&DataPath=RootNode/level1/cliënt
QueryString – “DataPath” = “RootNode/Level1/cli” (NOT OK)

Solution:

// when creating the url
string url = Server.HtmlEncode(“http://yoursharepoint/_layouts/projectx/viewdetail.aspx?ItemID=5&DataPath=RootNode/level1/cliënt).Replace(“&#”, “-amp-“)

// when checking the querystring
string dataPath = HttpUtility.HtmlDecode(Server.UrlDecode(Request.QueryString[“DataPath”].Replace(“-amp-“, “&#”)));

QueryString – “DataPath” = “RootNode/Level1/cliënt” (OK)

Advertisements
This entry was posted in Geen categorie. Bookmark the permalink.

One Response to ASP.NET C# Html Encoding/Decoding in combination with QueryStrings

  1. pariva says:

    nice article dude

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s