Monday, September 30, 2013

Create Your Own 500 Custom Error Page in ASP.NET


Step #1

Add a page to your website with the name 500.aspx. Style your page and put whatever content you want on this page.



Step #2

Add the following code to your Web.config file:

<configuration>
  <system.web>
    <!--For files-->
    <customErrors mode="On" redirectMode="ResponseRewrite">
      <error statusCode="500" redirect="/500.aspx"/>
    </customErrors>
  </system.web>
</configuration>

Step #3

Add the following code to your code behind page.

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.StatusCode = 500;
    }

This code will make the page respond with a 500 status code. If you don't do this, you will get code 200 which means OK. Bots and crawlers don't have eyes to see your content. They only care about the status code. If your status code says 500, then they will know it is a server error page.

No comments:

Post a Comment