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?