How to use Server.Transfer effectively

How to use Server.Transfer("default.aspx") to improve performance for navigating a website. When I use this, it does not change the URL in the address bar. How can I get the new server.transfer url. Or ( if not ) how can I get performance using Response.Redirect("default.aspx") .

+4
source share
2 answers

You need to understand the difference between Response.Redirect("page.aspx") and Server.Transfer("page.aspx")

Server.Transfer:

  • It does not change the URL, therefore it is not intended for debugging because you are not sure which page works in the browser since the URL may not change on more than one Server.Transfer statement.

  • It sends data from all form controls to the next page, starting from where you can access them using Request.Form["myTextBox"]

  • It works in only one domain; it will not be redirected outside the current domain name.

  • It will not cost round-trip on the server back from the browser, so it is faster compared to Response.Redirect .

Use your best solution when using Response.Redirect and when to use Server.Transfer . I would recommend using "Server.Transfer" if you want to send Control Forms data from one page to another, otherwise this will give you a debugging nightmare.

+5
source

I'm not sure I really like this approach, but if you insist on using Server.Transfer , you can use the HTML5 History API to change the URL in the address bar of the browser as soon as your answer reaches the browser and is processed there. Remember that only new browsers support this feature, but over time this should become a problem.

You will need a piece of JavaScript on your page to manage the current state of the story. It will look something like this:

 <script type="text/javascript"> window.history.pushState({ path: <pageurl> }, '', <pageurl>); </script> 

The <pageurl> must be installed on the server with the real URL of the page that you are actually processing in your Server.Transfer call.

There are many examples of how to use the html5 api history on the web so far, for example. http://html5demos.com/history .

+2
source

Source: https://habr.com/ru/post/1447219/


All Articles