我正在开发一个 Windows 服务,它将每 5 分钟获取一次 IIS 应用程序池状态信息并存储在数据库或文本文件中......比如运行或停止。
获取以下异常消息:
Microsoft.Web.Administration.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理附加信息:访问被拒绝。(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))
下面是我试过的代码:
static void Main(string[] args)
{
const double interval60Minutes = 5 * 5 * 1000; // milliseconds to one hour
Timer checkForTime = new Timer(interval60Minutes);
checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
checkForTime.Enabled = true;
Console.WriteLine("Waiting..");
Console.ReadLine();
}
public static void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
GetApplicationPoolNames();
}
public static string GetApplicationPoolNames()
{
ServerManager manager = new ServerManager();
string status;
//string DefaultSiteName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
//Site defaultSite = manager.Sites[DefaultSiteName];
string appVirtaulPath …Run Code Online (Sandbox Code Playgroud)