1. // Set the status code and description   
  2. Response.StatusCode = 302;   
  3. Response.StatusDescription = "Found";   
  4. // Specify the Location via the RedirectLocation property   
  5. Response.RedirectLocation = "Login.aspx";   
  6. // End processing of the page   
  7. Response.End()  

 

The Location HTTP header can alternatively be set using the Response.AppendHeader(name, value) method. That is, you could replace the Response.RedirectLocation property assignment in the code above with the following line of code:

  1. // Specify the Location via the AppendHeader method   
  2. Response.AppendHeader("Location""Login.aspx");  

The following code shows how to issue a 301 Moved Permanently redirect:

  1. // Set the status code and description   
  2. Response.StatusCode = 301;   
  3. Response.StatusDescription = "Moved Permanently";   
  4. // Specify the Location   
  5. Response.RedirectLocation = "NewPageUrl.aspx";   
  6. // End processing of the page   
  7. Response.End()  

posted on 2009-02-22 09:26  rosanshao  阅读(497)  评论(0编辑  收藏  举报