0

I am not sure if I will be able to explain this clearly.

I have a page on the website, lets say www.example.com/mypage/

Due to some business reason I would like to redirect the user to another page in the same website, say www.example.com/myotherpage/ as soon as the user enters www.example.com/mypage/ on the browser and hits go (I mean there is no referred url from which I can maintain any state).

Response.Redirect works just fine but due to the round trips it takes one hell of a time to load.

If I use Server.Transfer the loading time reduces significantly (less than half the time taken for Response.Redirect) but the url remains as it is i.e. www.example.com/mypage/.

My client would like to see the url of the new page in the browser i.e. www.example.com/myotherpage/.

On googling a little I found window.history.pushState (given here) but this is only applicable to latest browsers.

Also I need this on a mobile device so not sure if this code will work there.

I tried to search on the internet of any better ideas but not able to find one.

Any ideas will be of great help.

Thanks in advance!

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
samar
  • 5,021
  • 9
  • 47
  • 71
  • 1
    Why not simply use in your web.config? – jAC Jun 29 '17 at 13:20
  • A redirect should be almost no slower than opening the target page directly. If `due to the round trips it takes one hell of a time to load` then you may need to look at a better hosting solution, or perhaps pity your users for having such bad connections. Just one last thing that may help: make sure you do no unnecessary processing before the `Response.Redirect` is reached. – Peter B Jun 29 '17 at 13:24
  • I think httpRedirect will always redirect the said url. I do not want that. As mentioned in the question there is a business reason. Only when the reason is satisfied I would like to redirect else show the same page. – samar Jun 29 '17 at 13:25
  • @PeterB; the time observed is from 1 machine only and that too on the same network as the server. That is the reason I was able to comment on time difference between `Response.Redirect` and `Server.Transfer`. A request if you can elaborate on `hosting solutions`? I dont think there is any heavy processing before `Response.Redirect` – samar Jun 29 '17 at 13:30
  • A redirect itself is very fast, it should add no more than some milliseconds when on the same network. There might be a few things that can make it slower: (1) the server (webpage) takes time to process whatever before it decides to redirect, or (2) the server is overloaded / underdimensioned for its purpose, so either the initial page or the new page (or even both) react slow because of that. – Peter B Jun 29 '17 at 13:45
  • One final addition: try doing `Response.Clear()` before the `Response.Redirect()`. That will clear the buffer, so no unneeded HTML is sent along with the Redirect. If that makes a difference then you need to look into why there is so much HTML to begin with, when it clearly isn't needed and should not have been generated. – Peter B Jun 29 '17 at 13:48
  • @PeterB; let me try out the `Response.Clear()` thing. Will update you tomorrow. – samar Jun 29 '17 at 15:53
  • @PeterB; `Response.Clear()` not increasing the speed. Any thoughts around having the new url on the browser after `Server.Transfer`? – samar Jun 30 '17 at 05:40
  • That's not possible. With Server.Transfer, only the server is aware that another page gets executed, the browser sees just the output. Have you tried [Fiddler](http://www.telerik.com/fiddler) to see what traffic (requests & responses) is going over the line in all situations? Other than that, I'm afraid I can't help any further. – Peter B Jun 30 '17 at 07:20

0 Answers0