简体   繁体   中英

IIS 7: Redirect all request to Default.aspx

We want to redirect all request in an ASP.NET site to ~/Default.aspx to close the site. We are using IIS7. The site has paths like this that return a page:

http://test.com/operating

We are using url rewriting. We want requests similar to those to be redirected to ~/Default.aspx

http://test.com/ / http://test.com/ .aspx http://test.com/ / .aspx

We would normaly use something like this in web.config:

    <customErrors mode="On" defaultRedirect="Default.aspx">
        <error statusCode="404" redirect="Default.aspx" />
    </customErrors>

The problem with this is that it won't redirect folder url like this

http://test.com/ */

Thanks!

You can place a file named App_Offline.htm in the root of any ASP.NET application. This results in taking ANY .NET page request and outputting the contents of the htm file instead of the requested page. It isn't actually a redirect, but it is a very simple way to take an entire site down. If you need to, you can also use a standard meta refresh to send any requested to a new location (just remember not to do so to an ASPX file in the same site).

Have you tried HttpRedirect ? You'll have to install the feature first though.

You could do this if no files exist anymore.

  <system.webServer>
    <httpErrors errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/Default.aspx" responseMode="ExecuteURL" />
    </httpErrors>

I would write something like this in Global.asax (mind you, it's just an example, not production-ready code):

Application_BeginRequest(object sender, EventArgs e) {
    if(!Request.Url.ToString().ToLowerInvariant().Contains("default.aspx")) {
        Response.Redirect("Default.aspx");
    }
}

Also consider that this code will break non-ASP.NET requests when the application is running in Integrated Mode (in other it will redirect even requests for images and such).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM