1

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...

sabaedge
  • 79
  • 2
  • 10
  • Duplicate question-http://stackoverflow.com/questions/529551/how-can-i-remove-item-from-querystring-in-asp-net-using-c – coder Nov 24 '11 at 17:48
  • @Kiran but OP also needs to change page name from details to search. I think this other question should be useful http://stackoverflow.com/questions/352343/changing-browsers-address-bar-without-refreshing – daniloquio Nov 24 '11 at 17:50
  • @daniloquio-Yes I agree and I think he just gave us a sample that he wants similar to that. – coder Nov 24 '11 at 17:52
  • I don't really understand what you are try to archive and why. Can you please give us the bigger picture for the best possible advice and also include why a session variable can't be used. – Chris Felstead Nov 24 '11 at 20:39
  • actually, there is a view page to which we need to send some parameters like id,name,code etc. with this values, the data will be populated. Now we are using session. but if we open multiple tabs, then this is causing issue. so i like to pass this values as query string. the page should read them and delete it. is there any option like that? – sabaedge Nov 26 '11 at 02:46

1 Answers1

2

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.

Renato Gama
  • 16,431
  • 12
  • 58
  • 92