How does ASP. C # Control IIS services or application pool restarts in a program?

Source: Internet
Author: User

Stop the IIS Service
ServiceController sc = new ServiceController ("IISAdmin");
if (SC. status=servicecontrollerstatus.running)
Sc. Stop ();

Restart the IIS Service
ServiceController sc = new ServiceController ("IISAdmin");
Sc. Start ();

Restart process
Using System.Diagnostics;
Process.Start ("iisreset");

IIS application pool animation problem and automatic restart method

IIS on the network problems and related solutions, many, but many are more fragmented, there is no system solution; In addition, some solutions, specious, can not find the key points of the problem, this article on the problems we encountered and solutions, especially for IIS special permissions caused problems, The IIS application pool is an animation problem and a rare IIS restart command and automatic restart method.
One, 2003 application pool Auto dead, unable to recover, always appear Service unavailable common methods are as follows.
1, starting from IIS6.0 CPU resources are in the application pool within the limits, not like the previous iis.5. So the death of the pool is because the pool is pulled dead, you can not open the site when you see one of your application pool is disabled, there is a red fork. Your right mouse button launches the site and will automatically resume. This is probably due to several factors:
(1), you limit the resources of the application pool, the limit is too small, such as: 50 or less, this time if you this pool of the site under the CPU is too high, such as more than 50% then 5 minutes later he died automatically, manually set up by default application pool is more than the resources do not operate. The above situation is resolved: 1: Do not limit the CPU resources, (this is not desirable, do not restrict resources, some programs have a bug resource-intensive, the server will be pulled to death, you may not be able to operate the server.) 2: In excess of resources there is a choice to close, this shutdown default is a failure 5 times, 90 seconds to recover, the general default is available. The site can be automatically restored, this shutdown: not permanently closed, meaning that the resource is closed, and then automatically recovers the pool at a certain time. No operation is not recovery, this is a lot of people's misunderstanding.
(2), memory limit on the IIS6.0 application pool has virtual memory and maximum memory limit, if you set this. So the number of site visits will also appear suspended animation, it is not recommended to set here, by default.
2, is the Access database is too large or too many queries, this will also appear to pull the IIS dead, the solution, repair the Access database, or try to use less Access database to upgrade to SQL Server database, or technical innovation, such as now some web systems, wind news, Cms;pjblog, Zblog and other blog programs, all support the generation of static functions.
3, is the server itself memory is too small, the site runs of course need to use to memory, when the memory is not enough when the application pool will be dead to become disabled. Then only wait for the memory to be released to restore the application pool. This happens: then you have to consider adding memory or checking what program is taking up memory. such as MSSQL database, this is to eat large memory ah, it is best not to and Web server at the same time on a server. Many people use 1G of memory to do 2003 of the system, 2003NET structure is very memory-intensive, so do server Select 2003 also have to add memory to 2G or more well paid good. Memory is not enough, the above 1 o'clock, there is no way to operate, and can not automatically recover.
4, did not hit the SP1 patch will appear this IIS6.0 suspended animation problem, but now Microsoft are in the automatic update inside out the patch, generally you hit the latest patch will not appear after this problem. (So now the IIS feign animation is not very big with this relationship)
5, different sites with different application pool: According to your own actual situation, the site is the best independent one application pool, limit his resources more than automatic recovery, see above (1) talked about, so it does not affect other sites. Medium site: Multiple sites share an application pool, such as 5 sites with a pool, set his resource time, and so on. This allows them to be hyper-resourced and does not affect the sites of other application pools.
6, set the recovery time: a lot of people think that the shorter the recovery pool, the better, in fact, is wrong, each recovery of course is the memory back, but increased the burden of a server, when the server is busy, it is possible to cause other application pool dead. So we recommend setting a total of 1000 on the line. Other stand-alone pools can be set up to 600 if they are set according to the traffic on his website. The recommended settings for common use are too short.
7, the site will not be long after the automatic exit and re-login: The situation is that you set the collection time is too short, according to 6 points set it. Do not set what 20 points, 30 points such, so bad. Another reason is that the response setting time of the station is related, the setting is slightly longer.
8, Windows 2003 System IIS6 access to the local site when prompted "Service unavailable"; View the application pool for IIS, with the status prompt: No error is specified, and the application pool automatically stops running;
Use the Event Viewer to view the system error log and find the following prompt:
------------------
Application-specific permission settings do not grant local activation rights for the COM server application (CLSID {a9e69610-b80d-11d0-b9b9-00a0c922e750}) to the user NT authority\network SERVICE SID (s-1-5-20). You can modify this security permission by using the Component Services Administration tool.
Workaround, add permissions to the network service with access to the IIS services, as follows:
Click "Start"-"Control Panel"-"Administrative Tools"-"Component Services"-"Computer"-"My Computer"-"DCOM" option, select "IIS ADMIN Service" under it, right-hand Select "Properties", find "security", edit "Custom" in "Launch and Activation Permissions", Add the account "NETWORK SERVICE", give the account "local launch" and "Local activation" permissions, restart IIS and then access the same site, everything is fine.
9. Restart specific application pool commands and automatic restart methods in IIS
In the case where the operating system is Windows Server 2003 sp1+, you can partially restart the IIS application pool with the following command:
cscript.exe c:\windows\system32\iisapp.vbs/a "DefaultAppPool"
where/a represents alternatively, and "DefaultAppPool" represents the instance name of the application pool. If you want to set up an automatic restart of this application pool, you can try to place it in a batch and call this batch with a scheduled task. Many people feel that the task of planning is not safe, must be banned, in fact, the planning task of insecurity is based on other aspects of the premise of insecurity, if because of other aspects of insecurity, is placed in the execution of procedures, scheduled tasks to execute, which is not directly related to the scheduled task. Of course, switching off is going to reduce some of the security risks, which is good.

How does ASP. C # Control IIS services or application pool restarts in a program?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.