ASP.NET Custom 404 page not returning 404 code

by Bobby Cannon July 07, 2010 08:34 PM

After trying to setup my site for Google Webmaster Tools I found that my custom ASP.NET 404 page was not returning the 404 status code. The problem lies in the fact that my custom 404 page is a content form that uses a master page. The master page will override the content form status code. It displayed the correct custom page and told the browser that everything is OK (Code 200). This is considered a soft 404 or false 404. Google doesn't like this. I found many articles on the issue but the solution I want didn't seem to work. More...

Tags: ,

Programming

Forcing ASP.NET to generate valid XHTML code

by Bobby Cannon July 07, 2010 07:25 PM

Ever seen error like these when validating your ASP.NET web site using validator.w3.org?

there is no attribute "name". <form name="aspnetForm" method="post" action="../shop/StartPage.aspx?id=122"...

This will happen if you have the following doctype, indicating that the page content should be XHTML Strict:

However, using that doctype is not enough for ASP.NET to generate valid XHTML Strict code. To make it do that, make sure that the following is set in the system.web section of Web.config the default value is “Legacy”):

<system.web>
      <!-- other elements here -->
     <xhtmlConformance mode="Strict" />
</system.web>

Without that setting, ASP.NET will insert invalid attributes on the form tag and place the hidden input fields in invalid contexts. AFAIK, there’s no dialog where you can change this setting, you have to know it’s there. And now you do!

Notice:
The above solution only works in ASP.NET 2.0 only.

Tags: ,

Programming

Month List