[SOLVED] How do I command a page to reload in ASP.NET?

Issue

I am trying to figure out how to reload a page upon the user choosing to log out. This involves setting the logged in cookie to expired, and when the page reloads it will display as an unlogged in user.

// expiring the cookie for logout
ARCookie.Expires = DateTime.Now;
Response.Cookies.Set(ARCookie);

What seems to be a quick and dirty way of doing this is one of these three:

// reload the page
Response.Redirect(thisPage);
//or
Server.Transfer(thispage, false);
//or 
Server.TransferRequest(thispage, false);

Which of these is the best way, or is there another way of doing it that is preferred. I can’t find any kind of explicit “Refresh” command or action in the Page object. Is there one that I am perhaps missing somewhere?

Solution

This seems like the most reasonable approach:

Response.Redirect(thisPage);

Keep in mind that there isn’t really a concept of a “reload” in an HTTP request/response environment. The client issues a request, the server returns a response. A “reload” from the client’s perspective is to re-issue the same request. A “reload” form the server’s perspective is to indicate in the response that the client should issue a specific request, even if that request is right back to the same page. A redirect response is the standard way for the server to indicate this.

Answered By – David

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *