Just a simple redirect ASPX page

This post has been republished via RSS; it originally appeared at: IIS Support Blog articles.

You need to set a very simple redirect, from a specific location on your IIS web site or application, to a new URL? Then place this very simple default.aspx page at that location; in most of the cases, it works like a charm.

 

<%@ Page Language="C#"%>
<%
    Response.RedirectLocation = "http://new.location.net/optional/path";
    Response.StatusCode = 301;   //   301 = Moved Permanently   |   302 = Object moved   |   307 = Temporary redirect
%>

 

This is aimed at those of us too lazy to enable and use the HTTP Redirection feature of IIS. That would work with much better performance, and would cover some additional functionality, and doesn't need the .NET managed pipeline... But sometimes lazy is good :)

For those in need of complex redirects, the optional UrlRewrite module is THE solution, but you'll need to install and learn creating redirect rules.

Best of luck to all!

Leave a Reply

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.