IIS7 404 Errors

I have an ASP.NET 3.5 site running in IIS 7
I am trying to run 404 status code 404 for the first time.

Currently, if you enter

http://www.madeupsiteforexample.com/somethingmadeup

You will get 302 for 200.
I am trying to get this to throw away the 404 code first and display the 404 page where I have the setting (/FileNotFound.aspx)

The problem I am facing is either a 404 page is displayed with a 200 code, or IIS takes over when it sees a 404 status code and displays its own awful 404 page, and not my own created one.

I tried using the global.asax modules and set the status code for the code behind my 404 page. IIS takes care of all the results.

Here is my implementation of global.asax

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

Server.Transferring .
, , , , . , , , .

" " 404 IIS7?

+3
4

iis 7.. , ...

<httpErrors existingResponse="PassThrough" />

, . IIS7 customErrors Response.StatusCode?

, http://www.fidelitydesign.net/?p=21

+3

, , , .

0

, 404, " " "- " ( ).

0

Server.TransferRequest( IIS6) Server.Transfer, , - .

- Response.StatusCode = 404; FileNotFound.aspx web.config :

<system.webServer>
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="404" subStatusCode="-1"/>
    <error statusCode="404" prefixLanguageFilePath="" path="/FileNotFound.aspx" responseMode="ExecuteURL"/>
  </httpErrors>
</system.webServer>

, , 404 , , 404, , URL-, ..

if (Request.Url.ToString().Contains("?404;"))
{
    Response.StatusCode = 404;
    Util.DisplayMessage("The page you are looking for no longer exists. If you navigated to this page by clicking a link within this site please <a href='" + ResolveUrl("~/contact.aspx") + "'>contact us</a> to let us know.");
}

, .. , FileNotFound.aspx (.. / ) "~/" ) ( URL- ) . , , , FileNotFound.aspx , Context.RewritePath i.e.

Page.Header.Controls.AddAt(0, new LiteralControl("<base href='" + Request.Url.Scheme + "://" + Request.Url.Authority + VirtualPathUtility.ToAbsolute("~/") + "'/>"));
Context.RewritePath("~/");
0

Source: https://habr.com/ru/post/1794663/


All Articles