Why 503 Service Unavailable Error and How to Fix it?

In previous post, we have written tutorial about how to solve 401 unauthorized error in Asp.net core. In this tutorial, we will continue about other common error message that you or our clients often face it.

Error Message

Most of you will find this error message ‘Service Unavailable’ when running your Asp.net application. We will explain few reasons why it happened to your website.

Why 503 Service Unavailable?

The primary reason for this error is a stopped or disabled application pool. The application pool is the IIS component that initiates a worker process, which then allows the web server to process incoming requests for a website. When something is wrong with the application pool, the web server throws an HTTP Error 503.

Steps to Fix Service Unavailable

1. Check Rapid-Fail Protection

There can be various reasons for an application pool failure, such as an unhandled exception in the code, an expired password for the application pool identity, or something else. By default, IIS is configured to disable a malfunctioning application pool if its worker process faces five consecutive crashes within a period of five minutes. This setting is known as Rapid-Fail Protection, which is available under the Advanced Settings of an application pool. This is shown in the following screenshot:

  • Enabled—The value True indicates that the rapid-fail protection feature is active, which is the default. Set the value to False to disable it.
  • Failure Interval (minutes)—The time interval to specify the number of minutes (by default, 5) to count the failures for a process.
  • Maximum Failures—The maximum number of failures that are allowed within the time interval mentioned above (by default, 5).

2. Check Application_Error

A code bug may cause a site’s application pool crashed, thus resulting to Error 503. If you can change the source code, you’d better add the following logging function to Application_Error of Global.asax.cs. As thus, you’re able to find some clues in the log file if you confront this issue next time. Read the following code snippet.

protected void Application_Error(object sender, EventArgs e)
{
    string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “logs.txt”);
    using (StreamWriter sw = new StreamWriter(logFilePath, true, System.Text.Encoding.UTF8))
    {
        sw.Write(HttpContext.Current.Error);
    }
}

3. Your Site Use High Usage on the Server

Most hosting provider will put some limitation to their CPU and memory usage on the server. So, if your application hit high CPU usage on the server, the application pool on the server will automatically stop working. If your site utilize more than 10% CPU usage or more than 1 GB memory usage on the server, then you should optimize your codebase.

You are able to find CPU limit and memory limit for an application pool in your local Internet Information Services as it shows below.

Conclusion

The above factors are main reasons that why you receive 503 service unavailable error message. We hope above article help you to fix your issue quickly.

If you are looking for fast and secure ASP.NET hosting, you can visit our site at https://www.asphostportal.com. Our fully featured hosting already includes

  • Easy setup
  • 24/7/365 technical support
  • Top level speed and security
  • Super cache server performance to increase your website speed
  • Top 9 data centers across the world that you can choose.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *