[c#] HTTP Error 503. The service is unavailable. App pool stops on accessing website

There are number of posts on this and I have tried many a things by now. But to no avail. Myself a Winforms Developer basically, started working on this Web stuff few days back as my company is taking Web initiatives.

I have a ASP.Net project and I want to host it on local IIS. In Project properties -> Web settings I chose Use Local IIS Server and gave a url as localhost/MyApp. I tried accessing it on my firefox browser and received error as HTTP Error 503. The service is unavailable.

Previously I got many other errors and I one by one fixed them all. But struck with this one. These are the settings I have in my project

  1. Application Pool set to ASP.Net v4.0 Classic
  2. App Pool Enable 32 bit Application property is true
  3. App Pool is started
  4. Project build property set to Any CPU for Target framework

But I would like to mention a weird behavior. Following is something that I am facing

  1. Application Pool is Started
  2. I try to access my local website (by giving url as localhost/MyApp)
  3. I receive the error as HTTP Error 503. The service is unavailable
  4. Application Pool is Stopped

I have seen following link and I have already tried it. For the above behavior I reached here. According to this link, Computer name should not have . in it. I don't have any . in my Computer name but do have - in it. Also my domain name contains . in it. Moreover I can't change these settings as its my office laptop and our TFS settings are bound to our Domain and Computer Names.

Can anyone help me to understand whats happening? Please guide me. Thanks.

Edit

I have following code in Global.asax. Application_BeginRequest method is empty in same file.

protected override void Application_Start(object sender, EventArgs e)
{
    base.Application_Start(sender, e);
    String _path = String.Concat(System.AppDomain.CurrentDomain.RelativeSearchPath, ";",
                                         System.Environment.GetEnvironmentVariable("PATH"));
    System.Environment.SetEnvironmentVariable("PATH", _path, EnvironmentVariableTarget.Process);
    MyAppLog.Initialize();
    MyAppLog.WriteMessage("Application Started");
}

Update

As per the suggestions in Comment, I am able to run the website from Cassini.

This question is related to c# asp.net iis iis-7 localhost

The answer is


In addition to the steps outlined at this link from Orhan's answer, you may need to additionally remove the native module by going to IIS Manager > Server Root > Modules > Configure Native Modules. Select MfeEngine and then select Remove.


I had a similar issue. I solved it by adding my user to the "Log on as a batch job" policy under "Local Security Policy" > "Local Policies" > "User Rights Assignment".


Changing "Managed Pipeline Mode" from "Classic" to "Integrated" worked for me. It can be changed at Application Pools -> Basic Settings


For my situation is that my login password changed, while the application pool still uses the old one. So just click the "Advanced Settings" of your application pool and reset your "Identity".


Just to add to these Anniversary Update issues (thanks Microsoft) if the file you are missing is cgi.dll, ie your Event Viewer has

The Module DLL C:\WINDOWS\System32\inetsrv\cgi.dll failed to load.  The data is the error.

Then to fix this:

  1. Go to IIS Manager
  2. Select the very top row in the Connections panel (typically your PC name)
  3. At the very bottom of the right panel, under Management, you should have Web Platform Installer
  4. Once that loads, select Products
  5. In the search type in cgi then hit <Enter>
  6. Select IIS: CGI then click Add on the right and finally Install on the bottom
  7. After installing it should force you to restart your PC and you should be fixed.

In my case I checked event logs and found error was Cannot read configuration file ' trying to read configuration data from file '\\?\', line number '0'. The data field contains the error code.

The error code was 2307.

I deleted all files in C:\inetpub\temp\appPools and restarted the iis. It fixed the issue.


When I first time add the service and created the app pool for it. I did "iisreset" from command prompt, and it worked.


Most of Time, it was occured due to AppPool Setting.

Check the following to resolve this

  1. Check Apppool service is running.
  2. Check Identity of AppPool.
  3. Enter the new password if it has changed for that identity.

The following Images show these setting in IIS

enter image description here


For anyone coming here with Windows 10 and after updating them to Anniversary update, please check this link, it helped me:

https://orcharddojo.net/blog/troubleshooting-iis-apppool-crashes-status-503-after-windows-10-anniversary-update

In case link goes down: If your Event log shows that aspnetcore.dll, rewrite.dll (most often, but could be others as well) failed to load, you have to repair the missing items.

Here are two specific issues we've experienced so far and how to fix them, but you may bump into completely different ones:

"C:\WINDOWS\system32\inetsrv\rewrite.dll" (reference)
    Go to "Programs and Features" (Win+X, F) and repair "IIS URL Rewrite Module 2".
"C:\WINDOWS\system32\inetsrv\aspnetcore.dll" (reference)
    Go to "Programs and Features" (Win+X, F) and repair "Microsoft .NET Core 1.0.0 - VS 2015 Tooling ...".

Ok, I have another solution for one specific case: if you use WINDOWS 10, and you updated it recently (with Anniversary Update package) you need to follow the steps below:

  1. Check your Windows Event Viewer - press Win+R and type: eventvwr, then press ENTER.
  2. On the left side of Windows Event Viewer click on Windows Logs -> Application.
  3. Now you need to find some ERRORS for source IIS-W3SVC-WP in middle window.
  4. Probably you will see message like:

The Module DLL >>path-to-DLL<< failed to load. The data is the error.

  1. You have to go to Control Panel -> Program and Features and depending on which dll cannot be load you need to repair another module:
    • for rewrite.dll - find IIS URL Rewrite Module 2 and click Change->Repair
    • for aspnetcore.dll - find Microsoft .NET Core 1.0.0 - VS 2015 Tooling ... and click Change->Repair.
  2. Restart your computer.

I had the same issue with iis 8.5. After searching the eventViewer under windows Logs-->applications, I realized that I'm having a permission error for the machine.config file of the .net framework located at "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config". Giving it a permission for IIS_IUSRS solved my problem (right click the file-->properties-->security-->edit-->add-->IIS_IUSRS)


Will this answer Help you?
If you are receiving the following message in the EventViewer

The Module DLL aspnetcorev2.dll failed to load. The data is the error.

Then yes this will solve your problem


To check your event Viewer

  1. press Win+R and type: eventvwr, then press ENTER.
  2. On the left side of Windows Event Viewer click on Windows Logs -> Application.
  3. Now you need to find some ERRORS for source IIS-W3SVC-WP in the middle window.

if you receiving the previous message error then solution is :

Install Microsoft Visual C++ 2015 Redistributable 86x AND 64X (both of them)

Source


If you can run the website in Visual Studio debugger, then might be able to see where in your code the application pool is crashing. In my case, it was a function being called recursively an unlimited number of times, and that caused a stack overflow. Note: the Windows event log and the IIS logs were not helpful to diagnose the problem.


One possible reason this might happen is that you don't have enough disk space in your server machine. You can find more information in event viewer. if such thing happen, just stop the IIS, clean some free disk space and restart the IIS and then start the App Poll. enter image description here


If you have McAfee HIPS and if you see the following error in event viewer application log:

The Module DLL C:\Windows\System32\inetsrv\HipIISEngineStub.dll failed to load.
The data is the error.

Then the following resolved the issue in my case: https://kc.mcafee.com/corporate/index?page=content&id=KB72677&actp=LIST

Quote from the page:

  1. Click Start, Run, type explorer and click OK.
  2. Navigate to: %windir%\system32\inetsrv\config
  3. Open the file applicationHost.config as Administrator for editing in Notepad.
  4. Edit the <globalModules> section and remove the following line:
    <add name="MfeEngine" image="%windir%\System32\inetsrv\HipIISEngineStub.dll" />

  5. Edit the <modules> section and remove the following line:
    <add name="MfeEngine" />

  6. After you have finished editing the applicationHost.config file, save the file, then restart the IIS server using iisreset or by restarting the system.

In my case error message displaed in Windows Event Viewer -> Windows Logs -> Application was "The Module DLL C:\Windows\system32\inetsrv\rewrite.dll failed to load. The data is the error." Uninstalling rewrite module via installer solved the problem. I wasn't using any rewrite rules so I uninstalled rewrite module. Reinstalling the module may help the problem as well.


I was facing the same problem, and debugged it using the event logs. First it said that : "The description for Event ID 5059 from source Microsoft-Windows-WAS cannot be found".

I then turned on WAS using turn windows features on/off. Then i saw this in eventvwr "Microsoft-Windows-DistributedCOM cannot be found".

Finally I gave up and deleted the App Pool (that used to stop on accessing the website) and created it again, as it is. This resolved the problem.


I had a similar issue, all my app pools were stopping whenever a web request was made to them. Although I was getting the following error in the Event Viewer:

The worker process for application pool 'appPoolName' encountered an error 'Configuration file is not well-formed XML ' trying to read configuration data from file '\?\C:\inetpub\temp\apppools\appPoolName\appPoolName.config', line number '3'. The data field contains the error code.

Which told me that there were errors in the application.config at:

C:\Windows\System32\inetsrv\config\applicationHost.config

In my scenario, I edited the web.config on deploy with an element IIS clearly dislikes, the applicationHost.config scraped the web.config and inserted this bad element and wouldn't resolve until I manually removed it


I was experiencing this error and in my case the cause was that some time ago I modified the user password, and the 503 error didn't appears till I restarted the application pool.

So I fixed it setting the new password on Applications Pools / Advanced Settings / Identity / [...] / Set... / Password / Confirm Password


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."

Examples related to iis-7

Accessing a local website from another computer inside the local network in IIS 7 500.21 Bad module "ManagedPipelineHandler" in its module list HTTP Error 503. The service is unavailable. App pool stops on accessing website IIS - 401.3 - Unauthorized 500.19 - Internal Server Error - The requested page cannot be accessed because the related configuration data for the page is invalid ASP.NET Web API application gives 404 when deployed at IIS 7 WebApi's {"message":"an error has occurred"} on IIS7, not in IIS Express enabling cross-origin resource sharing on IIS7 How to fix 'Microsoft Excel cannot open or save any more documents' IIS 7, HttpHandler and HTTP Error 500.21

Examples related to localhost

Xampp localhost/dashboard Set cookies for cross origin requests Invalid Host Header when ngrok tries to connect to React dev server How to turn on/off MySQL strict mode in localhost (xampp)? What is IPV6 for localhost and 0.0.0.0? How do I kill the process currently using a port on localhost in Windows? How to run html file on localhost? Can't access 127.0.0.1 Server http:/localhost:8080 requires a user name and a password. The server says: XDB How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)?