Click here to Skip to main content
15,886,770 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I am having a task to write a C# application which starts and stops the application pool of IIS 7 server. Can any one have the Idea whether we can write a code which stops and starts the perticular app pool given as input.

Also, Please tell me whether we can do the above opertion remotely also.
Thanks in advance
Prashant
Posted
Updated 7-Nov-18 22:42pm
v2

Here we answer specific questions which members face during programming.

We can't work on the whole source code. You need to do that yourself.

If you face any difficulty while coding, feel free to come back here and ask another question with specific issue describing the scenario. Members will be happy to help you then.
 
Share this answer
 
Comments
Prashant Bangaluru 25-Oct-13 11:55am    
Sorry.. In haste and urgency I mentioned complet code.. Sure I ll try to write the code first and come back to community. Hope I ll resolve myself
Yes, that sounds nice. Good luck. :) Please accept the answer.
Prashant Bangaluru 25-Oct-13 11:57am    
I just edited the question also.. Can you please answer to my question.. I ll come back if I face issues
Check Restarting (Recycling) an Application Pool. You will get some idea. Else you can search in Google.
You need to take reference of System.DirectoryService. Then use the following code

C#
 string appPoolPath = "IIS://localhost/W3SVC/AppPools/myapppool";
//localhost will be actual server name.
            var appPool = new DirectoryEntry(appPoolPath);
            appPool.Invoke("Start", null);
            appPool.Invoke("Stop", null);
            appPool.Invoke("Recycle", null);


Just remember that administrative permission is needed to execute this code.
 
Share this answer
 
v4
Comments
Prashant Bangaluru 28-Oct-13 6:14am    
Hi Habib, Thanks for your response. I ll try the code now
S. M. Ahasan Habib 28-Oct-13 7:40am    
Let me know if any issue you face.
Ankita12 8-Nov-18 5:00am    
how to give administrative permission to execute this code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900