本文介绍了IIS 7.5自定义404错误页面不适用于Web根索引/默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IIS 7.5,我创建了一个自定义404(和403.14)错误页面,该页面在找不到静态文件的情况下显示来自数据库的内容.

Using IIS 7.5 I have created a custom 404 (and 403.14) error page that displays content from a database if a static file is not found.

换句话说,如果我浏览到 http://mysite.com/test/和一个物理在该位置找不到索引或默认文件,然后IIS执行我的404自定义错误页面,该页面将解析url并显示存储在数据库中的页面,或者提示说找不到该页面.

In other words, if I browse to http://mysite.com/test/ and a physical index or default file is not found at that location then IIS executes my 404 custom error page which parses the url and either displays a page stored in a database, or a notice saying the page cannot be found.

除了IIS不会显示Web根目录索引/默认页面的404页面之外,其他所有东西都运行正常.

Everything is working perfectly except that IIS will not display the 404 page for the web root index/default page.

网络根目录中没有文件-这是我观察到的结果:

There are no files in the web root directory - here are my observed results:

  • mysite.com:完全空白的页面
  • mysite.com/:完全空白的页面
  • mysite.com/index.aspx:正确显示我的自定义错误页面.
  • mysite.com/default.aspx:正确显示我的自定义错误页面.
  • mysite.com/index.htm:正确显示我的自定义错误页面.
  • mysite.com/anything_else/:正确显示我的自定义错误页面.

我的Web.config文件包含:

My Web.config file contains:

<httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/_page/" responseMode="ExecuteURL" />
    <error statusCode="403" subStatusCode="14" path="/_page/" responseMode="ExecuteURL" />
</httpErrors>

我想将主页的内容存储在该网站其余动态页面之类的数据库中,但是经过大量搜索后,当主页索引/默认页面出现时,仍然无法找到如何让IIS显示我的自定义错误页面的信息找不到.

I would like to store the contents of the home page in a database like the rest of the site's dynamic pages but after much searching still cannot find out how to get IIS to display my custom error page when the home index/default page is not found.

任何帮助/想法都将不胜感激.

Any help/thoughts would be greatly appreciated.

饲料

推荐答案

我最终通过使用Web根目录索引本身作为自定义错误页面而不是诸如"/_page/"之类的其他页面来解决了这个问题.

I ended up solving this by using the web root index itself as the custom error page instead of another page like "/_page/".

这适用于SSL重定向以外的所有内容,我认为这不是解决项目的足够大的问题.

This worked for everything except for SSL redirecting, which I decided was not a big enough issue to hold up the project.

在系统中,每个页面都显式设置为http或https.如果用户使用http地址导航到https页面,则他们将被重定向到https版本,反之亦然.但是,将根索引用作自定义错误页面意味着该重定向将不适用于主页,因为IIS出于某种原因不会将页面重定向到其自身.

In the system, every page is explicitly set to either http or https. If a user navigates to an https page using an http address then they are redirected to the https version and vice-versa. However, using the root index as the custom error page means that this redirection won't work for the home page because IIS will not redirect a page to itself for some reason.

如果任何人有解决该问题的想法,我将非常感谢您的想法.但是原来的问题已基本解决.

If anyone has any idea how to get around that problem I'd greatly appreciate your thoughts. But the original question is essentially solved.

希望阅读这篇文章对某人有帮助.

Hope reading this helps someone.

饲料

更新-2012年8月17日:

好吧,微软打了个电话(辛苦,但最终取得了丰硕的成果),但我终于找到了解决潜在问题的答案

Well, it took a support call to Microsoft (arduous, but eventually fruitful) but I finally found the answer to the underlying problem

当我第一次设置Web服务器时,出于安全原因,我没有安装目录浏览"模块.我不希望Web客户端能够看到文件结构.

When I first set up the web server, I did not install the "Directory Browsing" module for security reasons. I didn't want web clients to be able to see the file structure.

好吧,事实证明,一个人需要安装目录浏览模块(即使已禁用),以使IIS响应除200OK以外的任何内容(并生成空白的html页).

Well, it turns out that one needs to install the Directory Browsing module (EVEN IF IT IS DISABLED) to make IIS respond with anything besides a 200OK (and generate a blank html page).

安装后(出于安全原因,禁用该功能),IIS现在会以403.14禁止的错误作为响应,该错误已在我的web.config中正确重定向.

Once installed (and left disabled, for security reasons), IIS now responds with a 403.14 Forbidden error, which I already had correctly redirecting in my web.config.

这篇关于IIS 7.5自定义404错误页面不适用于Web根索引/默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 09:10