ASP.NET/IIS:所有文件类型均为 404
我在 web.config 中设置了 404 处理程序页面,但它仅在 URL 扩展名是 .aspx(或由 ASP.NET 处理的其他扩展名)时才起作用。 我知道我可以在网站选项中设置静态 HTML 页面,但我想要一个页面。 是否有任何选项可以为 IIS 中的所有请求扩展分配 ASPX 处理程序页面?
I set up 404 handler page in web.config, but it works ONLY when extension of URL is .aspx (or other which is handled by ASP.NET).
I know I can setup static HTML page in website options, but I want to have a page.
Is there any options to assign ASPX handler page for all request extensions in IIS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
供参考:
这是 IIS7 带来的几个好东西之一 - 所有页面都通过处理程序路由,以便您可以执行自定义 404 和 - 有用 - 任何文件的目录和文件级安全性(基于与 IIS7 之前的 ASP.NET 文件相同的 web.config 内容)。
因此,理论上“使用 II7”是一个答案(将成为及时的“答案”) - 但如果您没有在 W2k8(或更高版本)上托管/托管,那么当然它不是一个非常实用的答案。
For information:
This is one of the several nice things that IIS7 brings - all pages are routed through the handler such that you can do custom 404s and - usefully - directory and file level security for any file (based on the same web.config stuff as for asp.net files prior to IIS7).
So notionally "use II7" is an answer (will be "the" answer in time) - but of course its not a terribly practical one if you're not hosting/being hosted on W2k8 (or higher).
我唯一能想到的就是将所有扩展传递给 asp.net。
这样,所有类型的文件都会由 ASP.NET 处理,并且您的自定义错误页面将正常工作。
Only other thing i can think of is passing ALL extensions to asp.net.
This way all types of files get processed by asp.net and your custom error page will work.
web.config 只能为其网站控制的页面设置错误页面。 如果您有任何其他页面超出 ASP.Net 应用程序的权限,则可以在 IIS 中设置对它们的处理。 其中有一个用于配置 404 页面的选项,您可以将其指向您的自定义页面。
The web.config can only set up errors pages for pages controlled by it's web site. If you have any other pages outside the purview of the ASP.Net application, then you set up handling for them in IIS. There's an option in there for configuring the 404 page where you can point it to your custom page.
在 IIS 中,您可以为 404 错误设置自定义错误,并将其定向到站点属性中的 URL。
默认显示静态html
C:\WINDOWS\help\iisHelp\common\404b.htm
您可以将其更改为您站点上的相对 URL。
In IIS you can set a Custom Error for 404 errors and direct it to a URL in the site properties.
It shows a static html by default
C:\WINDOWS\help\iisHelp\common\404b.htm
You can change it to a relative url on your site.
您可以在 IIS 中设置通配符映射(应用程序配置/映射/通配符映射/ - 只需将 aspnet_isapi.dll 设置为可执行文件并取消选中“验证文件存在”框),该映射会将所有传入请求路由到您的应用程序 - 这样您就可以直接从中控制行为。
您不必在 IIS 应用程序设置中设置静态页面。 恕我直言,您应该能够从您的应用程序中设置有效的 url(例如 /error_handler.aspx),在出现特定服务器错误时将其用作登录页面。
You can setup wild card mapping in IIS (Application configuration/Mappings/Wildcard mappings/ - just set aspnet_isapi.dll as executable and uncheck the Verify that file exists box) that will route all incoming requests to your app - so you can control the behavior directly from it.
You don't have to setup static page in your IIS application settings. Imho, you should be able to setup valid url (e.g. /error_handler.aspx) from your app that will be used as landing page in case of specific server error.
在 IIS 应用程序配置中,您可以将通配符映射(“.*”)设置为 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
直接的问题是是否有选项将 ASPX 处理程序分配给所有请求扩展:是的,有。 我将很快讨论如何做到这一点。
首先,我认为“隐藏”的问题——你真正想要的答案——是是否有一种方法可以重定向除 ASPX、ASMX 等之外的页面的所有 404 错误。是的,有,这就是 <如果它能解决您遇到的问题,那么这是一个更好的选择。
要重定向 IIS 6 中的所有 404,请右键单击 Web 应用程序根目录(无论是其自己的站点还是主站点中的虚拟目录),然后选择“属性”。 从那里选择“自定义错误”选项卡。 在列表中找到 404 并将其更改为您想要的重定向。
现在,如果这还不够(我真的希望如此),是的,您可以通过 ASPX 处理程序运行每个页面。 然而,这样做的效率成本相当高——原始 HTML/图像服务比任何动态服务要快得多。
为此,请右键单击您的 Web 应用程序根目录并选择“属性”。 选择“主目录”选项卡。 单击“配置”; 将弹出一个新窗口。 从 ASP.NET 页面服务之一复制路径,然后将其用于通配符应用程序映射。
再次记住,大多数情况下这是错误答案。 它会对你的表现产生负面影响,相当于用电锯切火鸡。 我强烈推荐第一个选项,如果它适合您的话。
The direct question was whether or not there are options to assign the ASPX handler to all request extensions: Yes, there is. I'll discuss how to do that shortly.
First, I think the "hidden" question -- the answer you really want -- is whether or not there's a way to redirect all 404 errors for pages other than ASPX, ASMX, etc. Yes, there is, and this is the better choice if it'll solve the issue you're having.
To redirect all 404s in IIS 6, right click your web application root (whether it be its own site or a virtual directory in the main site), and choose "Properties." From there, choose the "Custom Errors" tab. Find 404 in the list and change it to the redirect you want.
Now, if that won't suffice -- and I really hope it does -- yes, you can run every page through the ASPX handler. However, doing so comes at a fairly high cost in terms of efficiency -- raw HTML/image serving is considerably faster than anything dynamic.
To do this, right click your web application root and choose "Properties." Choose the "Home Directory" tab. Click "Configuration;" a new window will pop up. Copy the path from one of the ASP.NET page serves, and then use it for a wildcard application map.
Bear in mind, again, this is the wrong answer most of the time. It will negatively impact your performance, and is the equivalent of using a chainsaw to carve a turkey. I highly recommend the first option over this one, if it will work out for you.