views:

103

answers:

1

My situation: when I deploy assemblies .NET in GAC, I get errors (Cannot access to xxx.dll because is in use for another process). The IIS use those dll (assemblies).

Which is the best way (more performance,quick and safe way) or all ways to stop, start IIS 6.0 Windows 2003 ? (for C#, .NET 3.5)

options, I think:

0). First step, detect IIS installed in machine.

1). Process.Start using commands: iisreset /stop, and iisreset /start

2). Use ServiceController class for get "World Wide Web Publishing Service" ( "W3SVC" ) and do stop

controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(timeoutSeconds));

and do start

controller.Start();
controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(timeoutSeconds));

3). Process.Start using tasklist command: taskkill /IM aspnet_wp.exe /F (use w3wp.exe in Win2003)

4). another options that I don't know ??

+2  A: 

You don't need to do all of these things.

Using just iisreset /stop then iisreset /start when you have finished your deployment will work.

It is fairly quick, and ensures a safe restart of IIS.

Edit:

You can carry out complete configuration of websites and virtual directories using WiX.

Wix sample for creating a website in IIS (will not work as is):

<!--  Create the web site in IIS --> 
 <Component Id="WebSiteComponent" Guid="<INSERT-GUID>" KeyPath="yes">
  <iis:WebAppPool Id="WebSiteAppPool" Name="WebSiteAppPool" RecycleMinutes="1740" QueueLimit="4000" IdleTimeout="20" MaxWorkerProcesses="1" Identity="networkService" /> 
  <!-- web site --> 
   <iis:WebSite Id="WebSiteIIS" AutoStart="yes" ConfigureIfExists="yes" Description="WebSite" SiteId="59" StartOnInstall="yes" Directory="SiteFolder">
   <!--  Host headers to enable web site to be hosted on port 80 --> 
   <iis:WebAddress Id="HostHeader" Header="myWebSite" IP="*" Port="80" Secure="no" /> 
   <iis:WebAddress Id="SecureHostHeader" Header="myWebSite" IP="*" Port="443" Secure="yes" />  
   <!--  download web site web application --> 
   <iis:WebApplication Id="WebSiteWebApplication" AllowSessions="yes" SessionTimeout="20" Buffer="yes" ParentPaths="no" ClientDebugging="no" Name="Default Application" WebAppPool="WebSiteAppPool" DefaultScript="VBScript" ScriptTimeout="90" ServerDebugging="no" /> 
   <iis:WebDirProperties Id="WebSiteProperties" Read="yes" LogVisits="yes" Index="yes" Execute="no" Write="no" AnonymousAccess="yes" AccessSSL="no" Script="yes" AspDetailedError="yes" /> 
   <!--  web service virtual directory --> 
   <iis:WebVirtualDir Id="WebServiceVDir" Alias="Service" Directory="WebServiceFolder">
   <iis:WebDirProperties Id="WebServiceVDirProperties" Read="yes" Write="yes" LogVisits="yes" Index="yes" BasicAuthentication="yes" AnonymousAccess="no" AccessSSL="yes" AccessSSL128="yes" Execute="no" Script="yes" AspDetailedError="yes" /> 
   <iis:WebApplication Id="WebServiceWebApplication" AllowSessions="yes" Buffer="yes" ClientDebugging="no" ServerDebugging="no" WebAppPool="WebSiteAppPool" Name="Default Application" SessionTimeout="20" ParentPaths="no" DefaultScript="VBScript" ScriptTimeout="90" /> 
  </iis:WebVirtualDir>
 </iis:WebSite>
</Component>

For another example see here:

http://strangelights.com/blog/archive/2004/10/08/179.aspx

fletcher
If you just need to recycle the services: `iisreset /restart`. And note on Win2k8/Vista and later this needs to be from an elevated command/PowerShell prompt.
Richard
Personally, I would deploy the files using a WiX installer that will sort all of this stuff out for me and allow a quick deployment to a new server should I need to do so.
fletcher
@Richard: any sample command/PowerShell? @fletcher: any samples of WIX ? I use Msbuild script for deploy.
alhambraeidos
@alhambraeidos - Wix takes care of the iis restart for you when you create a web site or virtual directory. It's done as part of the installation process. Editing post to include an example
fletcher
@fletcher: using iisreset command is better than use ServiceController for "World Wide Web Publishing Service" ( "W3SVC" ) ?
alhambraeidos
@alhambraeidos - iisreset does this behind the scenes anyway. Take a look at iisreset.bat to see what it's doing
fletcher
@alhambraeidos: Just execute iisreset from PSH (`iisreset.exe` is a standard part of Windows when IIS is installed). This is simpler than working out the PSH commands.
Richard