asewefy
asewefy

Reputation: 109

ASP.NET 4.5 Web Forms Custom 404 Page Best Practice

Well, for about one week, I have been searching the web, trying my own solutions and testing the results. But unfortunately I did not end up to the satisfying result that is needed.

Problem Details:

The problem is that; either using Response.Redirect(); method or declaring customErrors and httpErrors sections in the "Web.Config" file the very first status code sent to the browser is 302 then the 404.

Using Server.Transfer(); method or even modifying the QueryString[] collection within the Page_Load(); using System.Reflection this sends 404 status code directly to the browser but the "Page Name" (URL) is not my custom 404 page's name, but the requested non-existing page URL, which is a big problem (This can be checked using Google Chrome developer tools > Network pane), I have tried a workaround for this by changing the URL in the address bar of the browser using JavaScript window.history.pushState(); but this did not make a difference.

My Question is:

What is the best practice for a custom 404 page in ASP.NET Web Forms 4.5; Sending 404 HTTP status code directly as the very first response, preserving the 404 page URL in the address bar (without redirects and no JavaScript)?

Note: If any other information I am missing for an optimal 404 page to be detected and recognized by Google, please list.

Thanks.

Upvotes: 0

Views: 485

Answers (1)

asewefy
asewefy

Reputation: 109

I have solved the problem by using URL Rewrite Module 2.0 for IIS 7.5, after using this, 404 page was successfully recognized by testers.

I have figured out that there is no need to keep the 404 page address constant, it could be the URL of the non-existing page.

Thanks for Help.

Upvotes: 0

Related Questions