Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the URL in the browser URL Bar

Tags:

c#

asp.net

I am using server.transfer() method in my asp.net application to redirect the response. But I am running into the problem that it sets the previous page url (from where the original request for page was generated) at the browser url bar. I want to change the url in the browser. is it even possible??

I looked into it and i know that the Request has a url property but its read only. does any one know a way to change the url in the request?

like image 219
Arslan Faisal Avatar asked Dec 30 '25 11:12

Arslan Faisal


1 Answers

Use Response.Redirect(); instead of server.transfer(); and it redirects in the browser.

If you can't do taht, you could use pushState (at least where it's aviable) to change the URL, but it seems a bit of a overkill...

The best way is clearly to change

  server.transfer();

to

  Response.Redirect();

EDIT

as you want to have the maximum performance, you could should use Response.Redirect with two parameters, and set the second to true.

so instead of

  server.transfer(url);

you should have

to

  Response.Redirect(url, true);

That causes the current request to abort and force a instant redirect.

like image 175
ramsesoriginal Avatar answered Jan 01 '26 04:01

ramsesoriginal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!