3

I am redirecting to Error 404 page and want to issue 404 as a response code for google engine.

We are using IIS 6 in production environment :(

Code does 404 Handling in Global.ascx.cs in Application_Error()

if ((ex is HttpException && 404 == ((HttpException)ex).GetHttpCode()))
 {
    //Server.Transfer("~/404.aspx"); // Error with session state 
    Server.TransferRequest("~/404.aspx"); //This operation requires IIS 7 
    //Response.Redirect("~/404.aspx"); It will issue 302 then 404
     return;
 }

Server.Transfer

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

Response.Redirect

Issues 302 since it does client side redirect and then 404. I want to skip 302

Server.TransferRequest

This operation requires IIS integration pipeline mode

Global.asax Error handling: Quirks of server.transfer

How can I deal this problem in IIS 6?

why i am getting session issue with Server.Transfer? Is there a valid reason behind or it is a bug in ASP.Net Framework?

Community
  • 1
  • 1
Billa
  • 5,226
  • 23
  • 61
  • 105

1 Answers1

-2

If you still need correct 404 redirection, you can use this code:

Response.AddHeader("Location", "~/404.aspx");
Response.Status = "404 Not found";
Olga Golubeva
  • 307
  • 2
  • 8