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

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

问题描述

我使用下面的web.config code请求重定向到缺页到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或只是失踪的工作,它工作正常。如果它不工作,它只是加载一个标准的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。净处理程序不要求non-asp.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.

<一个href=\"http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx\">http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx

另一种选择尝试(比上面更清洁)被张贴作为一个答案在这里: http://stackoverflow.com/a/七十零万一千零六十二分之六百六十六万一千六百九十九

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

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

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