我想在使用asp.net c#的Web應用程序中回收IIS 6的應用程序池。C#回收IIS 6的應用程序池錯誤
protected void Page_Load(object sender, EventArgs e)
{
//Recycle IIS 6's App Pool
Recycle("localhost", "appPool_02");
}
void Recycle(string machine, string appPoolName)
{
string path = "IIS://" + machine + "/W3SVC/AppPools/" + appPoolName;
DirectoryEntry w3svc = new DirectoryEntry(path);
w3svc.Invoke("Recycle", null);
}
「appPool_02」是另一個應用程序池的名稱,上面的代碼是在「appPool_01」運行。
當我使用上面的代碼,它發生錯誤:
拒絕訪問(從HRESULT異常:0X80070005(E_ACCESSDENIED)) 描述:在當前web請求的執行過程中發生了未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.UnauthorizedAccessException:拒絕訪問(從HRESULT異常:0X80070005(E_ACCESSDENIED))
ASP.NET未被授權訪問所請求的資源。考慮將資源的訪問權限授予ASP.NET請求標識。 ASP.NET具有基本的進程標識(通常是IIS 5上的{MACHINE} \ ASPNET或IIS 6上的網絡服務),如果應用程序未模擬,則使用該標識。如果應用程序正在通過模擬,身份將是匿名用戶(通常爲IUSR_MACHINENAME)或經過身份驗證的請求用戶。
要授予對文件的ASP.NET訪問權,請右鍵單擊資源管理器中的文件,選擇「屬性」並選擇安全選項卡。點擊「添加」添加適當的用戶或組。突出顯示ASP.NET帳戶,然後選中所需訪問權限的複選框。
源錯誤:
Line 72: string path = "IIS://" + machine + "/W3SVC/AppPools/" + appPoolName;
Line 73: DirectoryEntry w3svc = new DirectoryEntry(path);
Line 74: w3svc.Invoke("Recycle", null);
Line 75: }
Line 76:
源文件:E:\的IProject \ iProgress \ iProgress \ t \ T.aspx.cs行:74
堆棧跟蹤:
[UnauthorizedAccessException:拒絕訪問。(異常來自HRESULT:0x80070005(E_ACCESSDENIED))]
[TargetInvocationException:異常被調用的目標拋出。] System.DirectoryServices.DirectoryEntry.Invoke(String methodName,Object [] args)+238 e:\ iProject \ iProgress \ iProgress \ T \ T.aspx.cs中的WE_T.Recycle(字符串機器,字符串appPoolName):74 WE_T.Page_Load(Object sender,EventArgs e)in e:\ iProject \ iProgress \ iProgress \ T \ T.aspx.cs:38 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)+35 System.Web.UI.Control.OnLoad(EventArgs e)+99 System.Web.UI.Control.LoadRecursive( )+50 System.Web.UI.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)+627
什麼是完整的異常追蹤? – 2009-09-20 05:33:05
「RPC服務器不可用」看起來像......無法找到IIS主機。 – 2009-09-20 06:01:26