简体   繁体   English

IIS 7错误代码

[英]IIS 7 Error Codes

I'm running a Sitefinity CMS website on IIS 7. I'm seeing a couple of weird results when I'm trying to return a 404 status. 我正在IIS 7上运行Sitefinity CMS网站。当我尝试返回404状态时,看到了一些奇怪的结果。

If I go to a URL like: 如果我转到如下网址:

www.mysitefinitywebsite.com/test.co.uk (I realise this is an invalid address, but someone entered it into the CMS) www.mysitefinitywebsite.com/test.co.uk(我知道这是一个无效地址,但是有人将其输入了CMS)

As the above is not an ASPX page, I believe IIS handles the error, with the following code: 由于上面的内容不是ASPX页面,因此我相信IIS使用以下代码处理了该错误:

    <httpErrors errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/404.aspx" responseMode="ExecuteURL" />
    </httpErrors>

The url in the address bar remains the same, my custom 404 page (/404.aspx) page is displayed, however a http status code 200 is returned. 地址栏中的url保持不变,显示了我的自定义404页面(/404.aspx)页面,但是返回了HTTP状态代码200。

If however the following url is typed in: 但是,如果键入以下URL:

www.mysitefinitywebsite.com/test.aspx - the ASPX error handler kicks in with the following config: www.mysitefinitywebsite.com/test.aspx-使用以下配置启动ASPX错误处理程序:

<customErrors mode="On" >
    <error redirect="~/Sitefinity/nopermissions.aspx" statusCode="403" />
    <error redirect="~/404.aspx" statusCode="404" />
</customErrors>

Again, my custom 404 page is displayed, however the url in the address bar changes to: 再次显示我的自定义404页面,但是地址栏中的网址更改为:

www.mysitefinitywebsite.com/404.aspx?aspxerrorpath=/test.aspx www.mysitefinitywebsite.com/404.aspx?aspxerrorpath=/test.aspx

And strangely if I check Firebug, a 302 code is returned for text.aspx and then a status of 200 for /404.aspx?aspxerrorpath=/test.aspx. 而且奇怪的是,如果我检查Firebug,则为text.aspx返回302代码,然后为/404.aspx?aspxerrorpath=/test.aspx返回200状态。

I don't completely understand whats going on here, it seems like IIS isnt responding with the status code at all - is this by design? 我不完全了解这里发生的情况,似乎IIS根本不响应状态码-这是设计使然吗? Seems completely crazy! 似乎完全疯了!

If it is by design, presumably the only way to resolve it is to programatically return the correct response code? 如果是设计使然,那么解决该问题的唯一方法就是以编程方式返回正确的响应代码?

Thanks in advance higgsy 在此先感谢时髦

When you use the <httpErrors> element and using executeUrl , you are serving dynamic content. 当使用<httpErrors>元素并使用executeUrl ,将提供动态内容。 If that content doesn't explcitly return the status code (an asp.net, asp, etc page) you need to set the existingResponse attribute to auto/replace/passthrough as you see fit. 如果该内容未明确返回状态代码(asp.net,asp等页面),则需要根据需要将existingResponse响应属性设置为自动/替换/通过。

The intent here is the web server can have a generic error and you may want to return a different or extended error code to your clients. 目的是Web服务器可能有一般性错误,您可能需要向客户端返回不同或扩展的错误代码。 This makes more sense for APIs where you might want a 404 to contain/return more info about what wasn't found, etc, etc. 对于API,您可能希望404包含/返回有关未找到的内容的更多信息,等等,这更有意义。

Take a look at the IIS.NET documentation on httpErrors for the existingResponse flag 看看httpErrors上的IIS.NET文档中的existingResponse标志

http://www.iis.net/ConfigReference/system.webServer/httpErrors http://www.iis.net/ConfigReference/system.webServer/httpErrors


As for ASP.NET, a 302 redirect on error is default behavior, which is what you see. 对于ASP.NET,默认行为是发生错误时重定向302,这是您所看到的。 The 404 is returned b/c the page you are redirecting to is programmatically setting the status code of the response. 在您正重定向到的页面上,以编程方式设置响应的状态代码时,将返回404页面。

The difference is simply causing by handling. 区别仅仅是由处理引起的。 In the first you are allowing IIS to handle the error before executing the ASP.NET pipe. 首先,您允许IIS在执行ASP.NET管道之前处理错误。 In the second, IIS passes off to the ASP.NET pipeline. 在第二个中,IIS传递到ASP.NET管道。 They are two different techs, hence the two difference behaviors. 他们是两种不同的技术,因此有两种不同的行为。 Rest assured with a little research you can make them both do the same. 放心研究一下,您可以让他们俩都做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM