2010-08-17 26 views
6

Tình huống của tôi: khi tôi triển khai các assembly .NET trong GAC, tôi gặp lỗi (Không thể truy cập xxx.dll vì đang sử dụng cho một tiến trình khác). IIS sử dụng những dll (hội đồng).Dừng và Bắt đầu IIS theo chương trình. Một cách nhanh chóng và an toàn

Cách nào là tốt nhất (hiệu suất cao hơn, nhanh chóng và an toàn) hoặc tất cả các cách để dừng, bắt đầu IIS 6.0 Windows 2003? (Đối với C#, .NET 3.5)

lựa chọn, tôi nghĩ:

  1. Detect IIS được cài đặt trong máy.

  2. Process.Start() sử dụng lệnh: iisreset /stopiisreset /start

  3. Sử dụng ServiceController lớp cho get "World Wide Web Publishing Service" ("W3SVC") và đừng dừng

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

    và đừng bắt đầu

    controller.Start(); 
    controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(timeoutSeconds)); 
    
  4. Process.Start() sử dụng lệnh: taskkill/IM aspnet_wp.exe/F (sử dụng w3wp.exe trong Win2003)

  5. một tùy chọn khác mà tôi không biết?

Trả lời

5

Bạn không cần phải làm tất cả những việc này.

Chỉ sử dụng iisreset /stop sau đó iisreset /start khi bạn hoàn tất việc triển khai của mình sẽ hoạt động.

Nó khá nhanh và đảm bảo khởi động lại an toàn IIS.

Chỉnh sửa:

Bạn có thể thực hiện cấu hình đầy đủ các trang web và thư mục ảo bằng WiX.

Wix mẫu cho việc tạo ra một trang web trong IIS (sẽ không làm việc như là):

<!-- 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> 

Đối với một ví dụ khác xem tại đây:

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

+0

Nếu bạn chỉ cần tái chế các dịch vụ: 'iisreset/restart'. Và lưu ý trên Win2k8/Vista và sau này điều này cần phải từ một lệnh nâng lên/dấu nhắc PowerShell. – Richard

+0

Cá nhân, tôi sẽ triển khai các tệp bằng trình cài đặt WiX sẽ sắp xếp tất cả những thứ này cho tôi và cho phép triển khai nhanh đến máy chủ mới nếu tôi cần. – fletcher

+0

@Richard: bất kỳ lệnh mẫu/PowerShell nào? @fletcher: bất kỳ mẫu nào của WIX? Tôi sử dụng kịch bản Msbuild để triển khai. – Kiquenet

2
# IISReset.ps1 - using PowerShell 
[array] $services = ('W3SVC','SMTPSVC','IISAdmin') 
foreach($service in $services) 
{ 
    $tst = Get-Service $service -ErrorAction SilentlyContinue 
    if($tst -ne $null) 
    { 
     Write-Host $service 
     Stop-Service -Name $service 
    } 
} 

[array]::Reverse($services) 
foreach($service in $services) 
{ 
    $tst = Get-Service $service -ErrorAction SilentlyContinue 
    if($tst -ne $null) 
    { 
     Write-Host $service 
     Start-Service -Name $service 
    } 
} 
Các vấn đề liên quan