ASP.NET/IIS: 404 for all file types

后端 未结 7 707
走了就别回头了
走了就别回头了 2020-12-20 21:51

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 webs

相关标签:
7条回答
  • 2020-12-20 22:40

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

    0 讨论(0)
  • 2020-12-20 22:43

    In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

    0 讨论(0)
  • 2020-12-20 22:43

    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.

    0 讨论(0)
  • 2020-12-20 22:45
    1. 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.

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

    0 讨论(0)
  • 2020-12-20 22:48

    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.

    0 讨论(0)
  • 2020-12-20 22:49

    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.

    0 讨论(0)
提交回复
热议问题