配置自定义ASP 404页面重定向的IIS7网站 [英] Configuring custom ASP 404 page with redirect for IIS7 website

查看:514
本文介绍了配置自定义ASP 404页面重定向的IIS7网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从迁移到IIS6 IIS7现有的网站,但正经历着建立404错误页面有些难度。我们的404的errorPage是这样的:


  • 自定义ASP页会针对特殊的URL地址的短名单的URL(如的http://例子.COM /限量优惠)。

  • 如果该URL是已知的,它重定向到该网页的实际的URL。

  • 否则访问者重定向到一个404状态code静态的errorPage。

使用IIS6这工作为标榜,但与一些IIS7事情发生了变化。当它遇到的errorPage被定义为其中一个状态code IIS7总是会显示配置的errorPage。在我们与404状态code静态的errorPage的情况下,这意味着IIS7会再次执行自定义的ASP页面。这将导致无穷的重定向。

我们已经发现通过添加Web.Config中的设置,这种行为可以被规避

 < system.webServer>
  < httpErrors existingResponse =直通/>
< /system.webServer>

不过,添加此我们自定义的ASP页面拒绝后重定向。使用Fiddler检查后似乎IIS7迫使404状态code,覆盖我们的302重定向。

谁能推荐另一种方法来解决我们的问题呢?


解决方案

我成功地使用类似的设置,我从迁移IIS 6到IIS 7。
我的web.config具有以下部分;


 < system.webServer>
    < httpErrors errorMode =自定义>
        <清除状态code =500子状态code = - 1/>
        <清除状态code =404子状态code = - 1/>
        <错误状态code =404prefixLanguageFilePath =PATH =/ 302page.aspresponseMode =ExecuteURL/>
        <错误状态code =500prefixLanguageFilePath =PATH =/ 500page.aspresponseMode =ExecuteURL/>
        <错误状态code =500子状态code =100路径=/ 500page.aspresponseMode =ExecuteURL/>
    < / httpErrors>
< system.webServer>


我通过IIS管理器中配置此相关的网站上,但如果你更方便可通过web.config文件为您代劳。

您可以根据是否应该是301,302或404添加条件标题。

404

  Response.Status =404未找​​到
Response.AddHeader位置,页面名

302(临时重新定向);

  Response.Status =301移动对象
Response.AddHeader位置,页面名

301(永久重新定向);

  Response.Status =301永久移动
Response.AddHeader位置,页面名

IIS网站的应用程序池使用集成的管道模式。和连接都是为现场调试节设置。

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:

  • A custom ASP-page checks the URL against a short list of 'special' URLs (e.g. http://example.com/limited-offers).
  • If the URL is known, it redirects to the actual URL of that page.
  • Otherwise the visitor is redirected to a static errorpage with a 404-statuscode.

With IIS6 this worked as advertised, but with IIS7 some things have changed. IIS7 will always display the configured errorpage when it encounters a statuscode for which an errorpage is defined. In case of our static errorpage with 404-statuscode, this means that IIS7 will execute the custom ASP-page again. This leads to infinite redirection.

We've discovered that this behavior can be circumvented by adding a setting in Web.Config

<system.webServer>
  <httpErrors existingResponse="PassThrough" />
</system.webServer>

However, after adding this our custom ASP-page refuses to redirect. After checking with Fiddler it seems that IIS7 forces the 404 statuscode, overwriting our 302 redirect.

Can anyone recommend another approach to solve our problem?

解决方案

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.

这篇关于配置自定义ASP 404页面重定向的IIS7网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆