Ensure dot.net site always runs - asp.net

I've created a very small monitor web-app, which periodically polls other websites to check if they're alive. If they're not I'm sent an e-mail so I can react (e.g. if the site responds 503)
However my problem is that the monitor web-app is shutdown when the AppPool recycles, and it's never started again because it gets no requests.
Is there a way to ensure it'll start again after a recycle, restart of the server or similar ?
Currently it starts a background thread in global.asax Application_Start, and the thread is then in charge of keeping the monitor web-app alive, by polling it as well as the other sites.
This way it'll get a HTTP request every so often. However this obviously only works for keeping it alive, when it has actually been started.
I've read a bit about IIS Warm Up modules, however the site is hosted on a server I've no influence on, so that's not possible.
The site is built using ASP.Net 4.0 and it runs on an IIS 7.5 server.
Hope you have an idea :-)

I use uptime robot to ensure my application is always spun up. The beauty of this system is it only asks for the headers of a page on your website and gets status codes like "200-ok", "404-not found", etc. every 5 minutes. This means that uptime robot does not add noise to Google Analytics as the page is never requested.
Seems to work like a dream for me and its FREE for upto 50 sites!

You should implement this as a windows service or console app run via a scheduled task. A web site is really not the appropriate type of application.

I Agree with tvanfosson but if you need it right now, you can still configure the application pool not to recycle.
http://technet.microsoft.com/en-us/library/cc753179(WS.10).aspx

It's better to make this up as a windows service or a scheduled console application. If you want to keep it as a webapplication then you can have 3rd party send pings to your application to keep it running. At my current client this is done with http://www.pingdom.com/ but there are other alternatives to it.

Related

IIS site goes hang when 100 or more users use the site

I have a site in which i am using web API through ajax that hosts on same IIS as a different site and both application pool are different. My web API is in MVC4 and I am using SQL server for data access some web API takes 0 sec and some takes between 2 sec to 8 sec . My site is centralized on azure server .
My Problem is when 100 or more users uses my site my IIS web API site goes hang and not respond any request more . For this i looked worker processes, there some request listed and server was not responding any request.CPU utilization is 50% and Memory is 19 % at that time.
Can i assigned 4 worker processes to web API sites for this issue but don't know how its work if i assigned multiple work processes to one site .
If u have any idea please share with me how i handle above situation?
I am certain that IIS is not causing this issue. If you think the requests are being blocked by IIS, you can check CurrentQueueSize or ActiveThreads.
You can also check executing requests from command line using 'appcmd list request' command. You will be able to see which requests are taking longer time to execute and blocking requests are usually at the top.
There is a high-chance that something in the code is blocking the requests.
By the way, you have tagged this query under 'azure'. Are you running it as Azure Web App? If yes, you can use 'Kudu' to diagnose the cause.
I am guessing you using an Azure VM (As from the description I see that you have access to IIS) .If that is the case,you can capture a hang dump of the process using debugdiag and do an automated analysis to figure out what is happening in your application code.
Before the issue occurs,Please go ahead and install DebugDiag on the server
Capture DebugDiag(capture consecutive hang dumps)
Launch DebugDiag Collection and Go to the Processes tab
Reproduce the issue
capture a hang dump
right click on the w3wp.exe process
choose the option Create Full Memory dump
Capture another dump after 30 seconds and then another after 30 seconds
You should have dumps captured in the folder C:\ProgramFiles\DebugDiag\Logs\Misc\
Right click on the dump file and choose the option Analyse Hang
Now the debugdiag automated hang analysis should tell you if there is any deadlock or any other issue in your code and also shows all the hung requests and where each requests are stuck.Also look at the stacktraces of the requests and see what it is doing.
Please feel free to update the question with more details if you need any help in analyzing.

Why would the Application_Start method being called a lot on my ASP.NET web service?

I have an ASP.NET Web Service (SOAP style) that is running in our production environment.
Our server guys have set things up such that things like starting and stopping of Windows services, etc., are sent via email to the appropriate parties.
Lately my boss has been getting emails about my ASP.NET web service:
The (My Web Service's Name) Application_Start method was called
Now I figure that what's happening here is that the service has gone so long since being called last that the server has unloaded it from memory and now it's being re-loaded again (the product that consumes this web service has declined in popularity, so this isn't too far fetched a theory).
However my boss tells me he's been getting this email "dozens" of times per day.
I suppose it's still possible that my theory above is accurate, especially given how it's spread out over 3-4 servers in our web tier, but is there any other explanation for why this might be happening so frequently?
At this point in time I don't know whether or not Application_End calls are being similarly emailed or not, or what the ratio is.
The application could be downloaded when some of the settings in <processModel> are exceeded. idleTimeout could be the one in your case, but also requestLimit and memoryLimit.
Also, and this is based on a true story, if you start any thread, run anything in a separate threadpool thread, or use the TPL, make sure that you catch any exception that might be thrown. Uncaught exceptions from those threads will kill the worker process. Check the application logs in the Windows event log. If this is the case, you should see the red icon application error signs around the same time that the emails go out.

background thread in asp.net application

i run a background thread in Application_Start() in global.asax
to use it like windows service
but applicaton_end fire when all session is ended in my website
i have a sms Business that work with webservice and i want to have agent in my server that
check incoming message like windows service
i increase session timeout to 10 hours but when i close browser application end fired and
my thread stop working
i cant change server properties
can i disable application_end to thread keep working?
I apologize to you because of poor english writing
You should make a separate program that runs as a service or a batch program to do that. Although ASP.NET persists static variables and such between page loads, you shouldn't be using it to run things in the background. There is no guarantee that things will keep running.
If you need something to happen on the user's end when something happens on the server (like a message received (like on facebook), someone responds to a request, or some other event is raised) you need to implement a polling system in javascript on the webpage that the user sees which uses AJAX (look it up...its such an awesome concept) to periodically talk to the server to see if anything happened. That is how Facebook chat works along with most webmail systems to check for new messages. The server doesn't talk to the browser...the browser asks the server if anything happened.
Here is an example of a chat program that uses AJAX: http://www.dynamicajax.com/fr/JSON_AJAX_Web_Chat-.html
It isn't exactly what you are doing, but it demonstrates the concept of trying to check something after the page has been loaded and making the user's browser respond.
Nay be use a .NET version of quartz-scheduler library (http://quartz-scheduler.org/) for defining and triggering a job based on the configuration (cron expresion).
iis automatically close website application when no session is open in website
for disable this you can change idle time in iis or read website link in global.asax (application_end) function to start a new session

Re-enable ASP.NET session that caused IIS hang

I'm trying to implement some fail safes on a client's web server which is running two of their most important sites (ASP.NET on IIS7). I'm going to set up application pool limiting so that if any w3wp process uses 90%+ CPU for longer than a minute then it gets killed (producing a temporary 503 Service Unavailable message to any visitors), and based on my local testing will be restarted within a minute - a much better solution than having one CPU-hogging process taking down the whole server for any length of time.
This seems to work, however during my fiddling on my local IIS7 instance I've noticed that if a request calls my "Kill.aspx", even when the site comes back up IIS will not serve the session that caused it to hang. I can only restart the test site from a different session - but as soon as I clear my cookies on the "killer" browser I can get to the site again.
So, whatever malicious behaviour IIS is trying to curb with this would not work against an even slightly determined opponent. In most cases, if excrement does hit fan it will be coding/configuration error and not the fault of the user who happened to request a page at that time.
Therefore, I'd like to turn this feature off as the theoretical user would have no idea that they need to clear their cookies before they can access the site again. I would really appreciate any ideas on how this might be possible.
Yous should be using ASP.Net Session StateServer instead of In-Proc (see msdn for details). That way, you session will run in different process and won't be affected by IIS crash.
Turn what "feature" off? If the worker process is reset (and your using in-proc session) then the session is blown away on a reset.
You might want to investigate moving your session storage to a state server or some other out of process scenario.
Also, you might want to set the application pool to use several worker processes (aka: web garden) this way if one process is killed the others continue serving content.
Next, as another option you might want to set up multiple web servers and load balance them.
Finally, you might want to profile the app to see exactly how they are causing it to spin into nothingness. My guess is that there are a number of code issues you are simply covering up with this idea.

Why does IIS7 take a long time

It looks likes if I don't visit my low traffic site for a day, it takes a long time for the first page to load. I believe it's probably because IIS7 shuts down the application when it receives no requests for a certain length of time.
How can I stop this from happening?
I have a dedicated server so I have all the access required to change things in IIS
There are two ways that you can handle this.
Modify the "Idle Timeout" value within the application pool. By default it will shutdown the application if there are no requests for 20 minutes
If you are using ASP.NET 4.0 you can use the new Auto-Start behavior to keep the app "Always Running" you can see this blog post for examples on how to configure it.
The app pool goes to sleep basically because it has no new requests to process in a certain amount of time.
There is a plug-in for iis that can fix this:
IIS: Application Initialization Module for IIS 7.5
Works great for both new deployments and idle applications.
Take a look at the application pool, check the advanced settings->process model->idle timeout (minutes). Set this higher than 20 mins. Sounds like the worker process is shutting down because its idle.
http://technet.microsoft.com/en-us/library/cc771956(WS.10).aspx
Cheers
tigger

Resources