0

We're running a MVC 5 application on .Net 4.7.2, hosting it with IIS 10. Investigating a application freeze for two minutes, I came to the conclusion that the configured IIS 404 error page and the application redirect logic bounced off each other.

Deleting the IIS error page, it gets even stranger: Now I see the default IIS error above our page when a 404 is thrown:

enter image description here

The "1" is right at the start of the body, therefore I guess it must be the IIS inserting the error message. I've removed the error page on the site as well as on the IIS itself. I've also changed the text on

%SystemDrive%\inetpub\custerr\\404.htm

to check if it still gets fetched, but that's not the case. Unfortunately, googling for this kind of issue, I usually find just questions about the 404 itself or general help for error pages like https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/, but none of them mention the appending of the message.

As we have our custom error page in the application, I don't want the IIS error to be shown. Is there some sort of hidden IIS logic I'm not aware of, which would do that?

Edit solution: Someone added a new IHttpModule, which performs a flush on the response. This is generally a very bad idea, see for example here: https://forums.iis.net/t/993221.aspx?Response+Flush+breaks+IIS+s+Custom+Errors+.

I guess because of the flush and the httpErrors existingResponse=auto, the IIS didn't clear the response stream but inserted his error beforehand. To circumvent the problem, I've configured it to existingResponse=PassThrough, as we have a custom error page anyway.

Matthias Müller
  • 3,336
  • 3
  • 33
  • 65
  • Do you need to delete any cookies? The cookie may be causing the redirection to old page that you deleted. Look at a sniffer to help solve issue. – jdweng Jun 03 '20 at 16:07

1 Answers1

1

It seems that you want to custom error pages, is that correct? As far as I know, Http error can be used to handling error thrown by the IIS itself, and the CustomError attribute is used to handle errors thrown by the DotNet code, therefore, I usually combine both features in order to custom pages for all errors on my side.
enter image description here
I suggest you try the below configuration for handling all errors. Here is an example configuration.
Webconfig.

      <customErrors mode="On" defaultRedirect="/MyCustomError1.html" redirectMode="ResponseRedirect">
          <error statusCode="400" redirect="/MyCustomError400.html" />
          <error statusCode="401" redirect="/MyCustomError2.html" />
    <error statusCode="403" redirect="/MyCustomError2.html" />
    <error statusCode="404" redirect="/MyCustomError2.html" />
    <error statusCode="500" redirect="/MyCustomError2.html" />
      </customErrors>
  </system.web>
  <system.webServer>
      <httpErrors errorMode="Custom" existingResponse="Auto">
<!--we need remove the default HttpError-processing logic.-->
          <remove statusCode="400" />
          <remove statusCode="401" />
          <remove statusCode="403" />
          <remove statusCode="404" />
          <remove statusCode="500" />
          <error statusCode="400" path="MyHttpError.html" responseMode="File" />
          <error statusCode="401" path="MyHttpError.html" responseMode="File" />
          <error statusCode="403" path="MyHttpError.html" responseMode="File" />
          <error statusCode="404" path="MyHttpError.html" responseMode="File" />
          <error statusCode="500" path="MyHttpError.html" responseMode="File" />
      </httpErrors>
  </system.webServer>

Result.
enter image description here
Please refer to the below discussion for more details.
What is the difference between customErrors and httpErrors?
here is an example of configuring custom errors on the IIS-side.
https://www.sherweb.com/blog/cloud-server/how-to-create-custom-error-pages-in-iis-7-5-with-asp-net/
Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • Probably I wasn't exactly clear, I don't want the custom error page from IIS, just the one from the application. It also really seem odd, that the IIS error message doesn't go away but is inserted at the beginning of the page, when the application error page is loaded. Many thanks for the information, I will dig through them. – Matthias Müller Jun 04 '20 at 05:19
  • Just to make clear: In the screenshot above, the numbers 1 to 5 are from MY application error page and the error message is from the IIS. Therefore, two pages are kindahow merged. – Matthias Müller Jun 04 '20 at 05:36
  • we might need to remove the default HttpError-processing logic like the above `Http errors` section of the webconfig. – Abraham Qian Jun 04 '20 at 09:48
  • Found the solution, it was in fact an application problem, but your links led to the hints I needed, thank you very much. – Matthias Müller Jun 05 '20 at 06:10