Posted By

LeeRJohnson on 11/08/08


Tagged

redirect c aspnet 301


Versions (?)

ASP.NET Redirect Page


 / Published in: ASP
 

URL: asp.net-redirect

  1. <%@ Page Language="C#" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <script runat="server">
  6. //Url to redirect this page to
  7. Uri urlRedirect = new Uri("http://design.leerjohnson.com");
  8.  
  9. private void Page_Load(object sender, System.EventArgs e)
  10. {
  11. //Provide link when not redirected
  12.  
  13. Page.Title += " to " + urlRedirect.ToString();
  14. aRedirectLink.InnerText = urlRedirect.AbsoluteUri;
  15. aRedirectLink.HRef = urlRedirect.AbsoluteUri;
  16.  
  17. //Set Response
  18. Response.Status = "301 Moved Permanently";
  19. Response.AddHeader("Location", urlRedirect.AbsoluteUri);
  20. }
  21.  
  22. </script>
  23.  
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head id="Head1" runat="server">
  26. <title>This page has moved</title>
  27. </head>
  28. <body>
  29. <h1>This page has moved to <a id="aRedirectLink" runat="server" /></h1>
  30. </body>
  31. </html>

Report this snippet  

You need to login to post a comment.