Setting StatusCode to error.aspx calls yet another Page_Load () function

The web.configerror page is set to/errorpages/error.aspx

<httpErrors errorMode="Custom" existingResponse="Replace" >
     <remove statusCode="500" subStatusCode="-1" />
     <error statusCode="500" path="/errorpages/error.aspx" responseMode="ExecuteURL" />
</httpErrors>

But when the page loads in the browser /errorpages/error.aspx, the status code is 200. This leads to various problems, for example, to the fact that when I have a JS file with the wrong URL, instead of receiving a specific error, I get a JS error, for example unexpected <(that the same logic is used for the page 404.aspx).

So, to fix this, inside error.aspx, in Page_Load(), I installed

Response.StatusCode = 500;

and the page returns with a 500 status code that can be seen in the browser.

, Page_Load() /errorpages/error.aspx, . , StatusCode is 200, 500, , IIS web.config, . StatusCode 200 500, .

, , , Global.asax.cs, :

Server.TransferRequest("/errorpages/error.aspx?someExceptionInfo=" + exceptionInfo);

, , , : error workflow

TransferRequest IIS . , - - - Production.

( ):

  • , ?
  • IIS, Response.StatusCode = ***?
  • , StatusCode?
+4

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


All Articles