Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS7 404 errors

I have an ASP.NET 3.5 site running in IIS 7
I am trying to have 404 throw a 404 status code first time round.

Currently if you type in

http://www.madeupsiteforexample.com/somethingmadeup

You receive a 302 follow by a 200.
I am trying to get this to throw a 404 code first time around and display the 404 page i have setup (/FileNotFound.aspx)

The problem i'm having is either 404 page is displayed with a 200 code, or IIS takes over when it sees the 404 status code and displays its own horrible 404 page and not my custom created one.

I have tried using modules, global.asax and setting the status code on the code behind of my 404 page. All result in IIS taking over.

Here is my Global.asax implementation

protected void Application_Error(object sender, EventArgs e)
{
    Response.TrySkipIisCustomErrors = true;
    Response.StatusCode = 404;
}

Now i did solve this problem by Server.Transferring my request.
This however causes all session to be null and any code referring to Session causes an exception. Also code trying to retrieve items from resource files cause exceptions.

Any suggestions or articles on the "right way" to do 404's in IIS7?

like image 390
WebDude Avatar asked Aug 23 '26 15:08

WebDude


1 Answers

i also got stuck on this for iis 7 .. you could try this one as it worked for me...

<httpErrors existingResponse="PassThrough" />

This person also had the same issue as you. IIS7 Overrides customErrors when setting Response.StatusCode?

here is an expiation of what is happening http://www.fidelitydesign.net/?p=21

like image 110
Kieran Avatar answered Aug 26 '26 07:08

Kieran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!