Configuring custom ASP 404 page with redirect for IIS7 website

前端 未结 3 1979
生来不讨喜
生来不讨喜 2020-12-07 04:08

We\'re migrating an existing website from IIS6 to IIS7, but are experiencing some difficulty in setting up the 404 error page. Our 404-errorpage works like this:

    <
相关标签:
3条回答
  • 2020-12-07 05:07

    I successfully use a similar setup which I migrated from IIS 6 to IIS 7. My web.config has the following section;

    <system.webServer>
        <httpErrors errorMode="Custom">
            <remove statusCode="500" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/302page.asp" responseMode="ExecuteURL" />
            <error statusCode="500" prefixLanguageFilePath="" path="/500page.asp" responseMode="ExecuteURL" />
            <error statusCode="500" subStatusCode="100" path="/500page.asp" responseMode="ExecuteURL" />
        </httpErrors>
    <system.webServer>
    

    I configured this on the relevant site via IIS Manager but you could do it via web.config file if easier for you.

    You can add conditional header depending on whether should be 301, 302 or 404.

    404;

    Response.Status = "404 Not Found"
    Response.AddHeader "Location", pagename
    

    302 (temporary re-direct);

    Response.Status="301 Object Moved"
    Response.AddHeader "Location", pagename
    

    301 (permanent re-direct);

    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", pagename
    

    IIS site's application pool uses Integrated pipeline-mode. And attached are settings for debugging section for site.

    settings for debugging section for site

    0 讨论(0)
  • 2020-12-07 05:10

    I encountered a similar scenario for a client the other week. The solution was to configure your <httpErrors> as follows:

    <httpErrors errorMode="Custom" existingResponse="Auto">
    
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" 
             prefixLanguageFilePath="" 
             path="/404.asp" 
             responseMode="ExecuteURL" />
    
      <remove statusCode="500" subStatusCode="100" />
      <error statusCode="500" 
             subStatusCode="100" 
             prefixLanguageFilePath="" 
             path="/500-100.asp" 
             responseMode="ExecuteURL" />
    
    </httpErrors>
    

    This works with Cactushop (written in Classic ASP) which has "friendly" urls and where they use the 404 handler page to parse the url and render products or list categories of products and so on.

    0 讨论(0)
  • 2020-12-07 05:11

    Alternatively you could look at using the IIS addon module: URLRewrite. This will allow you to set up custom SEO friendly URL's. You might find this something you want to look at to improve your application going forward rather than as a fix for your existing issue as may require some time to learn.

    There's some excellent articles, video tutorials and info on how to use this tool.

    0 讨论(0)
提交回复
热议问题