Forum Moderators: open

Message Too Old, No Replies

IIS logs show HTTP 404, but browser gets HTTP 500

Discrepancy between error codes

         

aakk9999

3:11 am on Dec 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am trying to find out why there is a discrepancy between error codes shown in IIS server logs and the actual error returned to browser. Here is some background info:

- IIS 7
- Rewrite module in use, set up to rewrite all requests to custom rewrite/redirect module
- Custom rewrite module handles fine URLs that are set up in custom rewrite or redirect tables (performing either redirect or transferring the request to a correct script)
- However, if the URL is NOT set up in rewrite/redirect tables, then it executes Server.TransferRequest to the originally requested URL
- If originally requested URL is for existing scripts, then the page renders fine.

However, if the request comes for non-existing script/non-existing URL (which is neither redirected nor rewritten), then I can see that Server.TransferRequest results in 404 in IIS logs, but browser receives HTTP 500

So the question is why does Server.TrasnferRequest(requestURL,true); correctly logs 404 in IIS server logs, but returns HTTP 500 to browser?

For example, if we have the following in custom rewrite/redirect script:

requestURL = "/non-existant-url"
Server.TransferRequest(requestURL,true);

Is there some error response that will be returned that needs to be checked after that call and then send programatically 404 based on the response? Or anything else?

Many thanks

Ocean10000

5:44 pm on Dec 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am guessing you have a 404 error page setup which it being transfered to. And it is this page which is generating the 500 error for what ever reason.

aakk9999

6:17 pm on Dec 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Many thanks, I will investigate. (I am not developer, just trying to help dev. agency to debug).

I am almost certain that there is no custom 404 page setup. Do you have any idea what would happen in this case for Server.TransferRequest that cannot work?

I have the following code that I think is the culprit and if I add few lines shown in bold below, would this fix the issue?

private void RenderPage(mNewRequestURL)
{
try
{
// transfer the URL
Server.TransferRequest(mNewRequestURL, true);
}
catch (Exception myEx)
{
throw myEx;

// unfortunately I have no idea what myEx above does but this is
// where the current (original) code finishes. If we add
// the code shown below, would this result in returning 404
// to the client if server transfer attempts to transfer
// to non-existing page? Or does this piece of code
// needs to be above "throw myEx" ?

log.Error("A: Server.TransferRequest attempt for non-existing URL - return 404");
Response.Clear();
Response.StatusCode = 404;
Response.Status = "404 Page Not Found";
Response.End();

}
}

Ocean10000

8:53 pm on Dec 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I see the bug.

Comment out the "throw myEx;" line and it will reach the 404 handling code which you want.

aakk9999

11:27 pm on Dec 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you :)