在web.config中使用自定义错误设置时出现IIS7“一个班轮"错误 [英] Getting IIS7 'one liner' error when using custom error settings in web.config

查看:48
本文介绍了在web.config中使用自定义错误设置时出现IIS7“一个班轮"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC应用程序,该应用程序在各个适当的位置返回404,偶尔返回500个状态代码.

I have an ASP.NET MVC application which returns 404 and occasionally, 500 status codes at various, appropriate points.

Response.StatusCode = (int)HttpStatusCode.NotFound;

设置这些状态代码之一时,还将适当设置TrySkipIisCustomErrors属性.

When I set one of these status codes, I also set the TrySkipIisCustomErrors property appropriately.

Response.TrySkipIisCustomErrors = true

我现在想做的就是配置IIS以传递这些错误,这些错误是我自己设置的,并捕获可能发生的任何其他错误(例如,静态文件中的404,而我没有向ASP发送请求) .NET或我的应用程序中未捕获的500个错误(该框架可能尚未设置TrySkipIisCustomErrors属性).

What I would like to do now, is configure IIS to pass through these errors, which I am setting myself, and catch any other errors that may occur (such as 404s on static files, where I am not sending requests to ASP.NET, or uncaught 500 errors in my application (where presumably the TrySkipIisCustomErrors propety will not have been set by the framework).

我的system.webServer/httpErrors节点如下所示:

My system.webServer/httpErrors node looks like this:

<httpErrors existingResponse="Auto" errorMode="Custom">
</httpErrors>

这将返回我自己的ASP.NET错误,在其中我设置TrySkipIisCustomErrors = true,以及未捕获的500s,静态文件404等的标准IIS错误页面.

This returns my own ASP.NET errors where I set TrySkipIisCustomErrors = true, and the standard IIS error pages for uncaught 500s, static file 404s etc.

然后我尝试像这样修改它:

I then tried modifying it like this:

<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="/Skins/Shared/Error/Error.html" defaultResponseMode="ExecuteURL">
  <clear />
</httpErrors>

我认为这应该显示我的自定义错误页面,而不是标准的IIS错误页面.但是,当我添加此代码时,我收到一行IIS错误(由于发生内部服务器错误,因此无法显示该页面."),它返回了500状态代码.

I believe that this should display my custom error page in place of the standard IIS one. However, when I add this code I get a one line IIS error ("The page cannot be displayed because an internal server error has occurred.") and it returns a 500 status code.

我认为这是由于配置错误所致,但是我一生无法理解自己在做什么错!

I assume this is due to an error in my configuration, but I can't for the life of me understand what I'm doing wrong!

我也尝试过这种方法,结果相同:

I have also tried this approach, with the same results:

<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="Skins\Shared\Error\Error.html" defaultResponseMode="File">
  <clear />
</httpErrors>

即使将重定向设置为完全不同的URL也会产生相同的问题.

Even setting a redirect to a completely different URL produces the same problem.

我一直在使用此页面作为参考:

I have been using this page among others for reference: http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx.

错误文件肯定存在,我可以使用浏览器直接将其击中.

The error file definitely exists, and I am able to hit it directly using a browser.

顺便说一句,我不确定我应该如何处理system.Web \ customErrors节点.这是仅IIS6的设置,还是以某种方式与ASP.NET相关?目前,我没有将其包含在我的web.config中.

As an aside, I'm not entirely sure what I should be doing with the system.Web\customErrors node. Is this an IIS6 only setting, or does it somehow relate to ASP.NET? Currently I do not include it in my web.config.

推荐答案

我知道这是一个老问题,但这与我最近才发现的过去几天来遇到的问题相同.对我有用的东西:

I know this is an old question but it's identical to the problem I have been having for the past few days that I just recently figured out. What worked for me:

尝试删除

<httpErrors>

完全来自web.config.

element from web.config entirely.

这篇关于在web.config中使用自定义错误设置时出现IIS7“一个班轮"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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