404重定向非aspx页面 [英] 404 Redirecting for non aspx pages

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

问题描述

我正在使用下面的web.config代码将请求重定向到错误的页面到404错误处理页面:

I am using the web.config code below to redirect requests to missing pages to a 404 error handling page:

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

当我寻找诸如missing.aspx等页面时,它的工作正常,但它不起作用没有.aspx扩展名的页面,如missing.asp或missing。当它不起作用时,它只会加载标准的IIS 7.5错误页面。

It works fine when I look for pages such as "missing.aspx" but it does not work for pages without the ".aspx" extension such as "missing.asp" or just "missing". When it does not work, it just loads a standard IIS 7.5 error page.

我做错了什么?我正在使用.net 4.我注意到其他人问同样的问题,但他们没有得到答案。

What am I doing wrong? I am using .net 4. I noticed other people asking the same question but they didn't get an answer.

谢谢!

推荐答案

正如 dbaseman 所述,这是因为asp.net处理程序不会被调用为nonasp.net文件。强制asp.net处理程序对所有请求进行操作的简单方法是在web.config中设置以下内容。

As dbaseman states this is because the asp.net handlers are not called for non-asp.net files. An easy way to force the asp.net handler to operate on all requests is to set the following in your web.config.

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
</system.webServer>

这将告诉IIS通过所有的托管模块运行所有请求,如.html,.jpg ,.css,.js等。这通常是因为它引入额外的处理和延迟而被皱眉。

This tells IIS to run through all of the managed modules for all requests such as .html, .jpg, .css, .js, etc. This is typically frowned upon as it just introduces extra processing and latency.

http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx

另一个尝试(比上述更干净)的选项作为答案发布在这里: https://stackoverflow.com/a/6661699/701062

Another option to try (cleaner than the above) was posted as an answer here: https://stackoverflow.com/a/6661699/701062

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

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