Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
515 views
in Technique[技术] by (71.8m points)

iis 7 - IIS7 Displays BOTH Its Own 404 Message & CF9 Message; Should Display Just Its Own

My goal seems simple.

I want IIS 7.5 to handle ALL 404 File Not Found requests, whether to static or dynamic (ColdFusion 9) content, and direct users to its custom 404 HTML page.

I believe that the IIS settings I need are existingReponse=Replace, errorMode=Custom, and a file path specified for the 404. That's what I've done.

With a ColdFusion 10 install, it works. With ColdFusion 9, for some reason both the static IIS 404 response AND the ColdFusion 404 response are sent to the client and displayed. Very weird.

I've tried all manner of alternate configurations, and there seems to be some problem with each approach.

Any ideas why IIS would fail to replace ColdFusion's 404 message? Is ColdFusion failing to communicate to IIS (via the appropriate header) that it's sending a 404? Is IIS being obstinate? Why would it be different with ColdFusion 10 and ColdFusion 9?

ColdFusion 9, via CFAdmin

Global Settings
- Missing Template Handler = [no path specified]

IIS 7, via IIS Manager

Configuration Editor -> system.webServer/httpErrors

    - allowAbsolutePathWhenDelegated = false
    - defualtPath  =  [no path specified]
    - defaultResponseMode = File
    - errorMode = Custom
    - existingResponse = Replace

Configuration Editor -> system.webServer/httpErrors -> Edit Collection

    - 404 Error
        path = [DriveLetter]:inetpubwwwrootCAESglobalerrorHandling404.html
        prefixLanguageFilePath = [none specified]
        respnseMode = File
        statusCode = 404
        subStatusCode = -1
    - 403 Error
        path = [DriveLetter]:inetpubwwwrootCAESglobalerrorHandling403.html
        prefixLanguageFilePath = [none specified]
        respnseMode = File
        statusCode = 404
        subStatusCode = -1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should actually solve more than one question/problem regarding ColdFusion and IIS 7.5. On my fresh Win2k8 R2/64-bit server running CF9 Standard, this has solved the issue of dual IIS and CF error template displays, eliminated the need to set IIS to display detailed error messages to the public and returns proper error codes to the client browser.

Unless you have a specific reason to uncheck it, leave ColdFusion's Enable HTTP Status Codes box checked in the CF Admin's Settings screen so CF can properly return status codes to IIS (some 404 solutions work by unchecking this box at the expense of losing those useful headers).

Step 1:
Configure a Missing Template Handler in CF Administrator. Mine is global to the server and kept in the ColdFusion webroot - which is separate from the IIS web root and whose default location is c:ColdFusion9wwwroot. This global template is 404handler.cfm and contains the following simple code, which you can expand upon:

<h1>404</h1>
<p>Page Not Found</p>
<cfheader
    statuscode="404"
    statustext="Not Found">

At this point, visit your web site and execute a bad ColdFusion url: http://[domain]/bogus.cfm. You will see both the IIS remote error screen/banner followed by your ColdFusion error screen. Check the header and it is a 404. This next step will solve the dual display problem.

Step 2:
Create a local 404 handler somewhere under the web root of an individual web site. I named this file 'local404.cfm'. It consists of the following:

<h1>404</h1>
<p>Page Not Found (local)</p>
<!--- 
demonstrate ColdFusion is functional 
with some simple output 
--->
<cfoutput>
<p>#now()#<br>#cgi.server_name#</p>
</cfoutput>
<cfheader
    statuscode="404"
    statustext="Not Found">

Go to IIS Manager and click on your individual web site. Click on Error Pages and edit this site's 404 handler. Set it to execute a url and make the url '/local404.cfm' (or whatever path is appropriate). Save your work. On the right side of the screen, click Edit Feature Settings and make sure that it is set for 'Detailed Errors For Local Requests and Custom Error Pages for Remote Requests'. Next, while still in IIS visit Handler Mappings and ensure that your ColdFusion handlers are set for a Path Type of 'File' (this step may not be necessary to solve this issue, but is per ColdFusion Lockdown guidelines).

Execute a bad ColdFusion url again: http://[domain]/bogus.cfm. This time you see only the ColdFusion error screen. Check the header and it is a 404. Do the same for a non-CF allowed URL such as http://[domain]/bogus.htm and a not-allowed one like http://[domain]/web.config. In all cases you should see the local error template executing, and the proper header of 404 being issued.

What is happening? Only the local IIS-based Coldfusion-driven 404 template is executing... As soon as you enable a local ColdFusion template in IIS, the global ColdFusion template is effectively and completely disabled. However it can be replaced as shown.

Apply the above to all web sites on the server, and you can delete your global CF missing template handler. A single global template would be preferable, but this method solves the problem and gives back complete functionality without creating security or SEO issues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...