Reputation: 1843
I have two files htmlpage1.htm and webform1.aspx
htmlpage1.htm contains a anchor tag with href="webform1.aspx?name=abc+xyz".
When i try to access the querystring in page_load of webform1.aspx, i get "abc xyz" (abc [space] xyz). I want exact value in querystring "abc+xyz"
Note: href value cannot be changed
Any help will be appreciated
Thank You.
Upvotes: 0
Views: 12956
Reputation: 101
Use this :
Request.QueryString["name"].Replace(" ","+");
// Refer below link for more info
http://runtingsproper.blogspot.in/2009/10/why-aspnet-accidentally-corrupts-your.html
Upvotes: 0
Reputation: 27415
This will Server.UrlDecode for you:
Request.QueryString["name"] // "abc xyz"
Option 1) You can re-encode
Server.UrlEncode(Request.QueryString["name"]); // "abc+xyz"
or get the raw query data
Request.Url.Query // "?name=abc+xyz"
Option 2) Then parse the value
Request.Url.Query.Substring(Request.Url.Query.IndexOf("name=") + 5) // "abc+xyz"
Upvotes: 7
Reputation: 3460
ASP.net will decode the query string for your. you can get the raw query string and parse it yourself if you want.
Upvotes: 1