ali raza

C#, .Net ,Asp.net and my thoughts

URL Encoding in asp.net

One of way while transferring data from one page to other page is Querystring. But one problem is with Querystring is that many characters are not allowed in url.  So we must have to send querystings while take limits in mind because alphanumeric and special characters including $-_.+!*’(),) are allowed. Usually browser does not tolerate special characters in Url, so much data is lost . In asp.net we can use the feature urlEncoding. With Url encoding special characters are replaced by escaped characters sequences starting with the percent sign (%) ,followed by a two-digit hexadecimal .The only exception is space character where character sequence %20 or + sign is used.  For this purpose asp.net provide us HttpServerUtility  class to encode data.

For example

String  CustomerName = “Ali Raza”;

Response.Redirect(“Blogpage.aspx?authorName=” + Server.UrlEncode(CustomerName));

 

Same time we can Querystring s initial values from Server.UrlDecode() method.

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

%d bloggers like this: