简体   繁体   English

在IIS7的自定义404错误页面中查找经典ASP错误

[英]Finding Classic ASP errors in a custom 404 error page in IIS7

We are migrating some Classic ASP sites from an IIS6 box to a new Server 2008 box running IIS7. 我们正在将一些Classic ASP网站从IIS6框迁移到运行IIS7的新Server 2008框。

We have been through a learning process with regard to custom errors and now have these working correctly and Server.GetLastError is now working. 我们已经过了关于自定义错误的学习过程,现在这些错误可以正常工作,并且Server.GetLastError现在可以正常工作。

The sites we are migrating use a bespoke CMS that utilises a custom 404.asp error page to pull content from a database depending on the URL. 我们正在迁移的网站使用定制的CMS,该CMS使用自定义404.asp错误页面从URL中提取数据库内容。 This, too, works perfectly. 这也很完美。

However, when the 2 are combined (eg we have a 500 error on a page that runs via the custom 404 page) we receive a completely blank page. 但是,当将2合并时(例如,在通过自定义404页面运行的页面上出现500错误),我们将收到一个完全空白的页面。 No error, no information nothing. 没有错误,没有任何信息。 Just a plain white page. 只是一张白纸。

Example 1: http://snavebelac.com/thisdoesnotexist results in the custom 404 page Example 2: http://snavebelac.com/st-test blank page. 示例1: http : //snavebelac.com/thisdoesnotexist结果显示在自定义404页面中示例2: http : //snavebelac.com/st-test空白页面。 This has an intentional 500 error within the custom 404 page. 在自定义404页内,这有意地出现500错误。

I assume that because it is running through the custom 404.asp error page that this somehow blocks the custom 500 error page from functioning. 我认为这是因为它正在运行自定义404.asp错误页面,从而以某种方式阻止了自定义500错误页面的运行。

Does anyone know how I might be able to configure the sever so that the custom 404 page fires but 500 errors are output to the browser as they were in IIS6 OR is there a way to configure the server to process the custom 404 as well as the custom 500? 有谁知道我如何能够配置服务器,从而触发自定义404页面,但是会像在IIS6中一样向浏览器输出500个错误,或者是否有办法配置服务器以处理自定义404以及定制500?

Thanks in advance. 提前致谢。

Check out the solution posted here - How can I properly handle 404 in ASP.NET MVC? 查看此处发布的解决方案- 如何在ASP.NET MVC中正确处理404?

The key is - Response.TrySkipIisCustomErrors = true; 关键是Response.TrySkipIisCustomErrors = true;

I had a similar problem, the solution is really weird but works for sure. 我有一个类似的问题,该解决方案确实很奇怪,但可以肯定地起作用。

I'll be very pragmatic, do the following. 我会非常务实,请执行以下操作。

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Auto">
  <remove statusCode="500" subStatusCode="-1" />
  <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/500.100.asp" responseMode="ExecuteURL" />
  <remove statusCode="404" subStatusCode="-1" />
  <error statusCode="404" prefixLanguageFilePath="" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>

The blank page will be "not blank" if you assure that it ends with: 如果您以空白页结尾,则该空白页将为“非空白”:

Response.Flush()

When IIS executes the code inside /500.100.asp it doesn't flush the response and it ends with a blank page. 当IIS执行/500.100.asp中的代码时,它不会刷新响应,并以空白页结尾。 I assure that "404" and "500.100" custom errors can be possible in IIS7.5/IIS8 and Classic ASP ;) 我保证在IIS7.5 / IIS8和Classic ASP中可能会出现“ 404”和“ 500.100”自定义错误;)

You have to configure your web.config to handle 500 status errors, like this: 您必须将web.config配置为处理500个状态错误,如下所示:

<system.web>
    <customErrors mode="On" defaultRedirect="frmError.aspx">
        <error statusCode="404" redirect="frmNotFound.aspx" />
        <error statusCode="500" redirect="frmError.aspx" />
    </customErrors>
</system.web>

Note the fourth line of code, where you say witch page has to be invoked since you got a 500 error. 请注意第四行代码,在该行中,您说到女巫页面,因为您遇到500错误,因此必须对其进行调用。

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

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