I’ve been developing this .NET class library as a COM object consumable by Classic ASP. Every time I go to build my project, it would tell me:
Unable to copy file "..\Core\bin\Debug\Core.dll" to "bin\Debug\Core.dll". The process cannot access the file 'bin\Debug\Core.dll' because it is being used by another process.
It turns out that the process that had a lock on my dll file was the IIS application pool process. After about a day of using remote desktop to login to the development server, opening up IIS and stopping the application pool, pressing Alt-Tab to get back to Visual Studio and swearing because Remote Desktop hijacks my Alt-Tab, painstakingly lifting my hand to my mouse, minimizing Remote Desktop, maximizing Visual Studio and building my library, trying the new build in my browser and swearing when I see “Service Unavailable” because the application pool is stopped… you get the picture.
This code enables you to stop and start your application pool from the comfort of your own browser. It also gives you your application pool’s status by monitoring AppPoolState.
IIS Application Pool restart .aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="iis.aspx.cs" Inherits="service.iis" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>IIS App Restart</title> </head> <body> <form id="form1" runat="server"> <div> Status: <asp:Label ID="lblStatus" runat="server" /><br/> <asp:Button ID="btnStop" Text="STOP App Pool" BackColor="IndianRed" ForeColor="White" runat="server" CommandArgument="dev.somesite.com" OnClick="stopAppPool" /><br /> <asp:Button ID="btnStart" Text="START App Pool" BackColor="Lime" runat="server" CommandArgument="dev.somesite.com" OnClick="startAppPool" /><br /> </div> </form> </body> </html>
Remember to replace “dev.somesite.com” in the CommandArgument attribute of the two buttons with the name of your application pool.
Codebehind .aspx.cs file
using System; using System.Web; using System.Web.UI; using System.Management; using System.DirectoryServices; using System.Web.UI.WebControls; public partial class iis : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(System.Environment.MachineName); status(); } protected void status() { string appPoolName = "dev.somesite.com"; string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName; int intStatus = 0; try { DirectoryEntry w3svc = new DirectoryEntry(appPoolPath); intStatus = (int)w3svc.InvokeGet("AppPoolState"); switch (intStatus) { case 2: lblStatus.Text = "Running"; break; case 4: lblStatus.Text = "Stopped"; break; default: lblStatus.Text = "Unknown"; break; } } catch (Exception ex) { Response.Write(ex.ToString()); } } protected void stopAppPool(object sender, EventArgs e) { Button btn = (Button)sender; string appPoolName = btn.CommandArgument; string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName; try { DirectoryEntry w3svc = new DirectoryEntry(appPoolPath); w3svc.Invoke("Stop", null); status(); } catch (Exception ex) { Response.Write(ex.ToString()); } } protected void startAppPool(object sender, EventArgs e) { Button btn = (Button)sender; string appPoolName = btn.CommandArgument; string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName; try { DirectoryEntry w3svc = new DirectoryEntry(appPoolPath); w3svc.Invoke("Start", null); status(); } catch (Exception ex) { Response.Write(ex.ToString()); } } }
You should probably stick this little page on a separate site using a different application pool 🙂
29 Comments
With the user of code, I am getting following error.
DEV1System.Runtime.InteropServices.COMException (0x80070005): Access is denied. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_NativeObject() at System.DirectoryServices.DirectoryEntry.InvokeGet(String propertyName) at _Default.status()
Try executing the exe with administrator role. Right click on the exe and click Run as administrator.
hi I am getting the following error?
could you advise me if there is anything i need to do differently because my machine is Vista? or how to rectify this problem i have named the ASPX file emailtest.aspx
and the code behind iis.aspx.cs ive been having a few problems when trying to include C# into my ASP pages so wondering if it is a vista related problem?
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type ‘service.iis’.
Source Error:
Line 1:
Line 2:
Line 3:
Source File: /sitehelpdesk/email/emailtest.aspx Line: 1
Hi, I also got to the point where I get this parser error message.
Where do I put this Codebehind.aspx.cs file ?
Did you ever figure out how to fix the parser error?
Jp62px http://fnYwlOpd2n9t4Vx6A3lbk.com
I am getting ComException: No mapping between account names and security IDS was done …
This when I am invoking these methods from a windows service. this however works in a windows forms application…Anything I am doing wrong.
thanks in advance
Kizhakk
Very funny pictures free xxx teen porn %-OOO
Hold the line, please teen horney porn 652
I’m on business top lolita
8[[
I’ll put him on pedo child gallery
%D
Just over two years Kid Porn Pedo
lqz
I love this site Lolita Nude
=DDD
I enjoy travelling top lolita pay sites 186
System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000) at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_NativeObject() at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) at _Default.StopIIS_Click(Object sender, EventArgs e)
This error typically happens because you do not have the Windows feature: IIS Metabase and IIS 6 configuration compatibility added to your server role. You can either add the role or use ServerManager from Microsoft.Web.Administration.dll (http://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager(v=vs.90).aspx) if you are just dealing with IIS7 and greater.
I’m sorry, he’s http://udyfopurykuf.de.tl girl naughty preteen Asian FOB girls are like handicap when it comes to sex. LIKE FKIN a star FISH!! WOW! SO BAD OMG!
I am curious to find out what blog system you
happen to be utilizing? I’m experiencing some minor security problems with my latest site and I would like to find something more secure. Do you have any recommendations?
Best Site Good Work http://www.zoji.com/1230648 video collections lolitas jpg the sounds she;s making are annoying as fuck but his dick is thick as hell, with a penis like that, he would do damage, in a good way
I was born in Australia but grew up in England http://community.parents.com/asumouooi/blog/2013/04/04/lolita_kingdom_nude_pics sven bbs lolita preteen Hum… i think you’re the most gorgeous and classy girl i have ever seen in my life, and that guy must be the luckiest man on earth. Damn, that was great.
Could you give me some smaller notes? free nude lolita guestbook someone needs to put a recent vid of her cause her tits are huge, they are the same size as eva angelina!
Which university are you at? nude lolitas thumbnails child she is soooooooooo hot
EXCELLENT!!
Very use full!!
Thank you very much
you save me!!
German
Exceptional post however I was wondering if you could write
a litte more on this subject? I’d be very grateful if you could elaborate a little bit further. Appreciate it!
For a nice and surfing on-line above 3 hours currently, having said that i certainly not discovered any kind of interesting content including your own house. It can be attractive truly worth enough personally. In my view, in case all webmasters as well as blog writers made superior information when you have, the web will certainly be a great deal more practical than ever before.
Aw, this was an exceptionally nice post. Spending some
time and actual effort to make a great article… but what can
I say… I put things off a lot and don’t manage to get nearly anything done.
I’d like some euros redpornblog
That girl is fit as fuck. I want to fuck her so hard and fast and cum on that stunning face of hers.
If you wish for to grow your experience simply
keep visiting this site and be updated with the most up-to-date information posted here.
On btnStop_Click Event, I am getting following error.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) — End of inner exception stack trace — at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) at restore.btnStop_Click
4 Trackbacks
[…] https://terrapinstation.wordpress.com/2008/06/12/restart-iis-application-pool-from-aspnet-page/ […]
[…] https://terrapinstation.wordpress.com/2008/06/12/restart-iis-application-pool-from-aspnet-page/ […]
[…] https://terrapinstation.wordpress.com/2008/06/12/restart-iis-application-pool-from-aspnet-page/ […]
[…] https://terrapinstation.wordpress.com/2008/06/12/restart-iis-application-pool-from-aspnet-page/ […]