I have a page default.aspx
When user browses this page as -
www.mysite.com/default.aspx/?&#&emp=1']];alert(2);[['1
there is an alert pop up. To prevent such attack, I would like to get the entire string typed in the browser, but unable to.
[NOTE : As you see, the text after ? need not be a query string. Here it is random chars. If it was a query string, I could get that in code.]
protected void Page_Load(object sender, EventArgs e)
{
string query = HttpContext.Current.Request.ServerVariables["URL"] +
HttpContext.Current.Request.ServerVariables["PATH_INFO"] +
HttpContext.Current.Request.ServerVariables["QUERY_STRING"];
}
In 'query' I only get /default.aspx/default.aspx/&
How can I get the entire string typed in the address bar.
UPDATE:
HttpContext.Current.Request.Url.AbsoluteUri
gives ?&
HttpContext.Current.Request.Url.ToString()
gives http://mysite/default.aspx/?&
This is not a duplicate of that Question, as my problem has chars, that are not query strings and also, the solutions in that Question did not resolve my problem. Thank you.
SOLUTION: Might help someone who have a similar concern. The fix was to deal this at Client side. I never knew that the part after # is not sent to the server side. Awesome suggestion by AmateurProgrammer & shadowed. Thank you