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

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

问题描述

我们正在将现有网站从IIS6迁移到IIS7,但在设置404错误页面时遇到一些困难。我们的404错误页面的工作原理如下:

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:


  • 自定义ASP页面根据一个简短的特殊URL列表来检查URL(例如<一个href =http://example.com/limited-offers =nofollow> http://example.com/limited-offers )。

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

  • 否则访问者将重定向到具有404状态码的静态错误页面。

  • 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.

使用IIS6,这可以像广告一样工作,但是对于IIS7,有些事情已经改变。遇到定义了错误页面的状态码时,IIS7将始终显示配置的错误页面。如果我们使用404-statuscode的静态错误页面,这意味着IIS7将再次执行自定义ASP页面。这导致无限重定向。

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.

我们发现通过在Web.Config中添加一个设置可以绕过这个行为

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

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

但是,添加这个我们的自定义ASP页面拒绝重定向。在与Fiddler检查后,似乎IIS7强制404状态码,覆盖我们的302重定向。

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?

推荐答案

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

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>


我通过IIS管理器在相关网站上配置了这个,但是你可以

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

您可以添加条件标题,这取决于是否应该是301,302或404。

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(临时重新直接);

302 (temporary re-direct);

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

301(永久重新直接);

301 (permanent re-direct);

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

IIS网站的应用程序池使用集成管道模式。附件是网站调试部分的设置。

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

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

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