Reputation: 101
i want to remove the query string from the url in C#. I will redirect to this page with a query string from another page like this, http://www.something.com/details.aspx?id=100. But the url in status bar should be changed to http://www.something.com/search.aspx.
I can't use sessions or 'post'. I tried implementing url rewriting,but i don't really understand how to set the rule to remove query string.
Anyone pls help...
Upvotes: 1
Views: 4331
Reputation: 16599
Its not a rule to remove the query string, but its KIND OF A REDIRECT (url rewriting), see.
if (this.Request.Path.Contains("/search.aspx"))
base.Context.RewritePath("/details.aspx?id=100");
You set this code at Global.asax Application_BeginRequest method.
Of course, instead of the Contains method you better use a regex.
This code means that you will reuse details.aspx but using search.aspx on your URL. So instead of redirecting user to /details.aspx?id=100 you will directly send him to /search.aspx and its done, you dont have to "remove the query string" as theres no query string to the user.
Upvotes: 2