简体   繁体   English

经典ASP IIS7自定义404处理程序

[英]Classic ASP IIS7 Custom 404 Handler

At witts end with this problem. 机智地解决了这个问题。

I am working on a busy site which we have migrated from IIS6 to IIS7, which uses a custom 404.asp handler to process SEO friendly URLS and return the correct content from included asp scripts. 我在一个繁忙的网站上工作,我们已经从IIS6迁移到IIS7,该网站使用自定义404.asp处理程序来处理SEO友好的URL,并从包含的asp脚本中返回正确的内容。

We have managed to get the 404 method to work on IIS7, but if there is a error in the code somewhere, we have set iis to run 500.asp which is designed to log the error and returns a useful message to the user. 我们已经设法使404方法可以在IIS7上运行,但是如果某处代码中有错误,我们将iis设置为运行500.asp,该错误旨在记录该错误并向用户返回有用的消息。

So the flow should be : 因此流程应为:

User types Friendly URL : eg http://www.sitename.com/testarticle/ Which does not exist and fires 404.asp 404 looks up "testarticle" in our database and returns the correct content. 用户类型友好的URL:例如http://www.sitename.com/testarticle/不存在并触发404。asp404在我们的数据库中查找“ testarticle”并返回正确的内容。 That all works.. 都行..

If error Should call 500.asp - Logs Error in our Log (Works) - Returns Msg to the screen (Not working - Just Get Blank Page) 如果错误应调用500.asp-在我们的日志中记录错误(Works)-将Msg返回到屏幕(不起作用-仅获取空白页)

This worked in IIS6, however in IIS7 the 500.asp logs the error in our log, but absolutely nothing is written out to the screen - We just get a blank screen. 这在IIS6中有效,但是在IIS7中500.asp在我们的日志中记录了错误,但是绝对没有任何内容写到屏幕上-我们只是得到了一个空白屏幕。 Very Frustrating. 非常令人沮丧。

We have tried changing what feels like every setting in IIS, and web.config but we can't get this to work. 我们尝试更改IIS和web.config中的每个设置的感觉,但无法使其正常工作。

Any help much appreciated.. Cheers 任何帮助,不胜感激。

I did a similar migration a little while ago and this is the web.config settings I ended up with (well just the relevant parts): 我前一阵子做了类似的迁移,这是我最终得到的web.config设置(以及相关部分):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="DetailedLocalOnly">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/common/404.asp" responseMode="ExecuteURL" />
            <remove statusCode="500" subStatusCode="100" />
            <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/common/500.asp" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

Note the web.config section used. 注意使用的web.config部分。 When done using the customErrors element it did not work for me. 使用customErrors元素完成后,它对我不起作用。 This was the only way I could get both URL rewriting using a custom 404 error page and custom 500 errors working in Classic ASP. 这是我既可以使用自定义404错误页面重写URL,又可以在Classic ASP中使用自定义500错误进行URL重写的唯一方法。 Hopefully that helps you. 希望对您有帮助。

So you get a blank page? 这样您会得到一个空白页? 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”自定义错误;)

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

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