ASP.NET Service Unavailable 503 Error Using a Shared Windows Server

ASP.NET Service Unavailable 503 Error Using a Shared Windows Server

This post is for the analysis and resolution to the Service Unavailable 503 Error when you host a ASP, ASP.NET or ASP.NET MVC website with a shared Windows server, though you may not have had such an issue locally ever before.

You may find so many related topics at Google search, but almost all of them are not assumed that you’re using a shared Windows server and you don’t have full permission to the whole server, including Event Log, W3SVC service configuration, etc. This is the difference you learn here.

Simply, there are only 4 high possible reasons for such an error.

  1. incorrect .NET CLR version & Managed Pipeline Mode of the site application pool
  2. incorrect Enable 32-Bit Applications of the site application pool – typically for a Classic ASP website
  3. fault error of codebase – try to catch the errors in Global.asax.cs
  4. the limitation of the IIS application pool set by your shared web hosting provider forces the site process halted

Check .NET CLR Version & Managed Pipeline Mode

If you set an incorrect version, your website cannot launch anyway. In a shared Windows server, some web hosts provide only a dedicated application pool per hosting account. That means, when you have multiple websites using the different .NET framework hosted with 1 account, they’re conflict with each other.

For an example. You firstly deploy the site X.com using .NET 2.0 successfully. Later, after you deploy another site Y.com using .NET 4.0, you may get the 503 error at X.com, because the deployment of Y.com updated the shared application pool to .NET CLR Version 4.0.

This is the same logic to Managed Pipeline Mode – Integrated and Classic.

Locally or leveraging remote IIS management, you can click the Advance Settings of your website application pool via the Internet Information Services Manager as the following screenshot.

Service Unavailable 503 Error - .NET CLR Version

If your web host doesn’t allow remote IIS management, you shall check the site configuration at the web-based control panel. Take WebSitePanel as an example. Navigate to “Web > Web Sites > {Your Site} > Extensions Tab”, and select the right ASP.NET pipeline as the following screenshot,

Service Unavailable 503 Error - .NET CLR Version and Pipeline Mode - WebSitePanel

Check Enable 32-Bit Applications

Another reason of Service Unavailable 503 is Enable 32-Bit Applications. You can find this setting in the screenshots of IIS or WebSitePanel above. These are the most frequent reasons below for the error caused by this setting,

  • The Classic ASP website is able to work only in 32-bit environment. When you have a .NET website using 64-bit environment hosted together with a Classic ASP site, or when you start a website with 64-bit initialized by the web host, you may have the error.
  • Your .NET website is compiled with the specified 32-bit or 64-bit, but hosting with the other mode.
  • Your .NET website depends on some library which must run under 32-bit or 64-bit. For examples. The Ole DB Driver 8.0 to load Office Excel files requires 32-bit environment.

Logging in Application_Error

A fault error of code execution (*code bug) may lead the application pool of a website crashed in result to Service Unavailable 503 also. If you’re able to modify the source code, please try to add logging function into Application_Error of Global.asax.cs of the web project. Then you may find some clues in the log file when you experience such an issue at the next time. Read the code snippet below,

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);
	}
}

The Limitation Of Your Web Host

The steps above are nearly what you can debug from your end when you’re using a shared Windows server. Otherwise, it’s highly possible that the issue comes from the limitation of the web hosting company.

If you get the Service Unavailable 503 Error occasionally and randomly, particularly, when you have large concurrent requests at a time, you upload a large file, or you have a complicated logic to response a specific request. It’s highly possible that this is caused by the limitations of the site application pool configured by your web hosting provider.

  • CPU Limit
  • Private Memory Limit

Almost no hosting company has the CPU and private memory limitation public, but 100% of them have such limitation to avoid the server over used by a single user. Try to ask the provider for these 2 parameters, and know the right expectation. If your website consistently takes over 500 MB memory or 10% of server CPU locally, you may need to have a performance tuning and optimization of your codebase, or upgrade to a dedicated Windows server (much more expensive surely).

CPU Limit

The latest IIS 7.x/8.x allows hosting companies to configure the CPU limit (percent) of an application pool that the worker process of your site is allowed to consume a specific number of CPU usage at maximum. If the limit is exceeded when your website has a peek traffic or computes a complicated logic (sometimes a defect) at a time, the worker process of your site is killed or throttled. Before the process is re-launched after a limit interval in minutes, you shall experience Service Unavailable 503 Error.

You can find this setting for an application pool in the local IIS as the following screenshot. Unfortunately, it’s invisible to neither remote IIS management nor almost web hosting control panels.

Service Unavailable 503 Error - IIS CPU Limit

This screenshot indicates: when your website occupies 15% of the server CPU usage, the worker process of the site is killed and will be re-launched in 5 minutes so that you must see Service Unavailable 503 Error during this period.

Private Memory Limit

Similar to CPU Limit, the private memory limit also leads the same issue as the following IIS screenshot. That means, when your website consumes over 256 MB memory, the worker process is recycled automatically in result to a temporary Service Unavailable 503 Error before the restart.

Service Unavailable 503 Error - IIS Private Memory Limit

Usually, 256 MB is the amount of private memory limited by many web hosts, though only a few web hosts clearly introduce it. For an example. Host4ASP.NET – a professional ASP.NET hosting provider, has 3 plans named Basic, Advance and Business. When you look into the plans apparently, you may only see the difference on the disk space, addon domains, or hosting sites on 1 account. In fact, they introduce a limitation of private memory 256 MB, 512 MB, and 1 GB of these 3 plans at the feature page.

Conclusion

There are many personal or startup web hosting companies without rich experience in the market. They keep life through simply over-selling a Windows server. Instead of taking your hear white, I personal recommend you going with the following budget and reliable choices.