Efficient Page Reloading in ASP .NET

Today I ran into a situation where I needed to change some session state information on an ASP page I was developing and have it instantly update the current page. This can be accomplished with the following code:

//Stop processing and reload the current page
Server.Transfer(Request.Path);

Server.Transfer() transfers execution to a specified ASP page that does not force a new page request. This is more efficient than the old Response.Redirect() way of doing things.

Request.Path will get the path of the current request. Which, more simply put, will point straight back to the page you are currently on.

Put these two together and you have a recipe for success when you want to make your page stop processing and begin again.

Creative Commons License

What do you think?