HTTP Error 503. The service is unavailable in IIS? [duplicate] - c#

This question already has answers here:
HTTP Error 503, the service is unavailable
(40 answers)
Closed last year.
I published my Web Api (framework 4.5) in this path:
C:\inetpub\wwwroot\MyWebAPI
In my IIS, I converted this folder to an app
When i try to access this URL http://localhost/MyWebAPI/api/client/1 the message appears:
Service Unavailable
HTTP Error 503. The service is unavailable.
Why is this?
Update
My App Pool is set to be "STOP". When I turn it on, it goes back to "STOP"

I found the solution
Click on Application Pools under the tree with your machine name,
on the right side, click click on Advanced Settings,
in Process Model change the "Load User Profile" to false
Start your application and restart your IIS
The error will surely change, in my case the error changed to this one
"Config Error: This configuration section cannot be used at this path.
This happens when the section is locked at a parent level. Locking is
either by default (overrideModeDefault="Deny"), or set explicitly by a
location tag with overrideMode="Deny" or the legacy
allowOverride="false"."
I have found the solution for this other problem here
Config Error: This configuration section cannot be used at this path

This is a fairly old thread, but I stumbled across it with the same issue. For me, the resolution was to reset the App Pool user. I was starting the site, but the app pool would just stop. No logs, nothing. I recently had to change my windows password and the app pool user (me) was using the old password :-)
(note my website continued to work for a few days with the old password until I did an iisreset which is when the problem started)

You might stop App pool, start it and error will be gone.

Run the following commands in PowerShell in administrator mode.
Stop-Service -Force WAS
Remove-Item -Recurse -Force C:\inetpub\temp\appPools\*
If the above command not working, delete files manually.
Start-Service W3SVC

Related

File gets "locked" while moving operation and iis give 401 error

I have a windows service run with local system account
What my program does is :
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
File.Move(archivePath, outputPath);
Relevant folder is application folder of iis where its application pool's identity is ApplicationPoolIdentity located under c:\MyAppFolder.
My windows service does its few times a day, and my clients checks if any new version exists every 5 minutes(0,5,10,15...) and download that file.
Time to time, file is somehow get "locked" on filesystem then
iis gives 401 error
File cannot be deleted
My first question how can I repro this situation?
One patch is done by colleagues is:
var fs = File.GetAccessControl(outputPath);
fs.SetAccessRuleProtection(false, false);
File.SetAccessControl(outputPath, fs);
Although this patch, it seems error occured again,
I may apply, this solution as well.
Are those solutions are enough or necessary?
Again my first question is important "repro issue" and understand why this happens.

What are the possible causes for IIS to throw a ThreadAbortException and recycle the worker, with IIS logging "IIS configuration change"?

I started seeing errors in a .Net MVC web app hosted on Appharbor whilst a background thread was running - after careful analysis - I can't work out the cause.
Firstly, the exception I noticed is a ThreadAbortException.
However, this is really just signifying that the thread is being killed. Before the thread is killed, you can see a new worker is created by IIS and Application_Start is called on the same machine. Once the new application is up and running, IIS kills the old app and new requests are handled as expected.
At the same time, IIS logs a message of:
ShutDown Message: IIS configuration change
HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown
ShutDown Stack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
at System.Web.Hosting.PipelineRuntime.StopProcessing()
In .Net Health Monitor Logging you get a:
Message: Application is shutting down. Reason: Configuration changed.
Event Detail Code: 50004
A quick google reveals the source code I suspect is the reason for the error:
if (!HostingEnvironment.StopListeningWasCalled && !HostingEnvironment.ShutdownInitiated) {
// If GL_STOP_LISTENING wasn't triggered, the reset is likely due to a configuration change.
HttpRuntime.SetShutdownReason(ApplicationShutdownReason.ConfigurationChange, "IIS configuration change");
}
source: https://github.com/Microsoft/referencesource/blob/master/System.Web/Hosting/IPipelineRuntime.cs
My first thought was to check timestamps for file changes, both in the bin folder and the main application directory - however, this error is thrown without any file changes. Given it only happens on Appharbor, I can't attach to the process and debug that way. I've also monitored memory usage, and don't see any issues there.
The source code states:
If GL_STOP_LISTENING wasn't triggered, the reset is likely due to a
configuration change.
Hence, what else could be causing the error and application recycle, if the web.config / other config files aren't changing?
There are many reasons, which are listed by this helpful blog entry.
Application pool settings
The processModel element of machine.config
Memory limit
Request limit
Timeout
IIS configuration change should happen when something (anything) changes in your IIS application configuration or code. Examples:
Change in web.confg
Change in any dll, aspx, etc...
In any of those cases, IIS application will recycle. In addition, IIS will recycle your process every 29 hours by default, but that will probably not be called "IIS configuration change"
It looks like this was a Microsoft bug.
Unexpected ASP.Net application shutdown after many App_Data file
changes occur on a server that is running Windows Server 2012 R2
Hotfix: https://support.microsoft.com/en-us/kb/3052480
Last Review: 09/08/2015 16:29:00
Once this hotfix was applied, the errors went away!

Cannot start service

I have 2 other services running on a server and they start and stop without a problem, however one of them will not start. I can't see any difference in their implementation or config files. I'm receiving the following messages when attempting to start the service after installing it with InstallUtil:
The service is not responding to the control function
more help is available by typing NET HELPMSG 2186
NET HELPMSG 2186:
Explanation: The service cannot run your command at this time
Thanks very much in advance!
This is most likely due to service installed, then uninstalled and now you are trying to install again. Reboot the machine and try again.
UPDATE
According to the event log error, you are trying to run the service as the current logged in user (I guess you are connected using remote desktop). This is not the correct approach, you need to run the service as the LocalSystem. In the project properties window, change the identity of the service.
UPDATE 2
In the design view of the service/component class, click on serviceProcessInstaller1 (or similar) and then in tmhe properties you see a drop down: Account with 4 entries: User/LocalNetwork/LocalService/LocalSystem. Make it LocalSystem
On Start event can you put
try
{
//...
}
catch(Exception ex)
{
EventLog.WriteEntry(ex.Message + ex.StackTrace);
}
and watch whats happening?
or
attach (Tools > Attach To Process) your process to Visual Studio for DEBUG. You can see whats happening with debug, but EventLog works good aswell.

IIS7 restart issue

I have a webservice on one of my websites which restarts the websites app pool.
The problem Im getting is the IIS7 app pool keeps stopping with the following warning and then error:
Warning:
A process serving application pool 'appPoolNameHere' exceeded time limits during shut down.
Error:
Application pool 'appPoolNameHere' is being automatically disabled due to a series of failures in the process(es) serving that application pool.
The code I am using to do this is:
try
{
var serverManager = new ServerManager();
var currentPoolName = SettingsManager.AppPoolName;
if (!string.IsNullOrEmpty(currentPoolName))
serverManager.ApplicationPools[currentPoolName].Recycle();
HttpRuntime.Close();
}
catch (Exception ex)
{
var exceptionManager = ExceptionManagerFactory.GetExceptionManager();
exceptionManager.LogException(ExceptionManager.Severities.Critical, ex,
"App Pool restart failed");
}
I am not getting any exceptions being thrown here, but the app pool is stopping, this doesnt happen all the time and is very hard to replicate, I have tried several different things even just hitting the hell out of that service and sometimes its fine other times it dies.
Is there anything I can do to fix this?
The reason I have to restart it is due to an external config file to the webconfig which deals with the url redirects which is updated from the admin system.
Thanks for any help with this.
Well I seem to have sorted (not fixed) the issue, with some tape and sticky-back-plastic.
The solution
Changed app pool setting: Rapid-Fail Protection to false
This stops IIS from killing the app pool after several failed requests to it.
I also added in retry system, so if the recycle request fails it waits for 10secs and tries again, it will do this 5 times before giving up and sending out an exception notice.
This has fixed the problem, and everything seems to be working well again, although something about this screams this is wrong!! at me.
Only if IIS would monitor other files in a website and restart the app pool when it saw a change.
I didn't work with Microsoft.Web.Administration namespace, but what about unloading application domain and sending request to your website so that to start application again?
Good example (2nd point) by Peter Bromberg how to do this.
Update.
Reading error stack
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()
I thought of most common reason: insufficient rights. All administrative actions require administrative rights. When code above is executed, which user account is impersonated? IUSR? Switch to any admin for that block and it should work without exception.

How can I avoid timeout errors while debugging a web service in visual studio 2008

I am using a console application to call web service methods and I am stepping through the code using the debugger in vs2008.
Sometimes I need to stop and think about things, and compare values. Not talking hours, just a few minutes, at this point the web service times out, how can I avoid this, so that the web service does not time out at all.
Thank you
Ok, now a serious answer, found at:
http://bytes.com/groups/net-web-services/628561-increase-default-webservice-timeout-globally
Increase the Timeout property of the web-service-proxy.
MyWebServ obj = new MyWebServ();
obj.Timeout = -1; // -1 for forever otherwise in milliseconds
Increase the timeout value in http-runtime tag in web-config of ASP.NET
project./app.config if the web consumer application is Windows.
Increase the timeout value in http-runtime tag in web-config of Web Services
project.
You can turn the timeout off by stopping the application pool from recycling:
In the IIS console, go to the app pool properties and set "Ping Enabled" to false
(hope this helps! - is my first answer on here)
I hade the same Problem and in my case the Solutions mentioned here did not really help.
After long searching time i found the solution somewhere else, i had to disable worker process pinging for an Application pool by following command:
appcmd set apppool /apppool.name: string /processModel.pingingEnabled: false
alternativly you can configure this in the User Interface by:
Open IIS Manager
On the Connections pane, expand the server node and click Application Pools.
On the Application Pools page, select the application pool and then click Advanced Settings in the Actions pane.
For the Pinging Enabled property, select False to disable pinging, and then click OK.

Categories