Why:
It always good to send query string values in encrypted format. Encrypted URLs prevents sending illegal requests or invalid data to the application server. Users or attackers cannot see the request details of the URL as they are encrypted.
Example
Before encryption,
http://localhost:60608/EncryptURLDemo/Default2.aspx?text=amol
After encryption,
http://localhost:60608/EncryptURLDemo/Default2.aspx?q=dSoxSTYQLHY3arcO+hfCO7uMyRNnIpRCoUqk0oyR80c=
How:
Method 1: Manually encrypt / decrypt query string parameter
- Copy EncryptionHelper.dll into Bin directory of your web application.
- To encrypt query string values,
string url=string.Format("~/Default2.aspx?text= {0}",EncryptionHelper.Encrypt("valuehere")); - To decrypt query string values,
if (Request.QueryString["text"] != null) Text = EncryptionHelper.Decrypt(Request.QueryString["text"]);
Method 2: Automatic encrypt / decrypt query string using HttpModule
- Copy EncryptionHelper.dll into Bin directory of your web application.
- Add the following lines to the web.config’s section:
<httpModules> <add type = "QueryStringModule" name = "QueryStringModule" /> </httpModules>
Downloads:
Assembly: Download Now
Source code and Demo: Download Now