如何使用ServerManager的阅读IIS站点,不是IIS快递,从类库或如何提升进程处理类库? [英] How to use ServerManager to read IIS sites, not IIS express, from class library OR how do elevated processes handle class libraries?

查看:580
本文介绍了如何使用ServerManager的阅读IIS站点,不是IIS快递,从类库或如何提升进程处理类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Microsoft.Web.Administration.ServerManager ,我一直有一些问题,一些实用的方法。使用插图的下面死的简单的代码。

I have some utility methods that uses Microsoft.Web.Administration.ServerManager that I've been having some issues with. Use the following dead simple code for illustration purposes.

using(var mgr = new ServerManager())
{
    foreach(var site in mgr.Sites)
    {
        Console.WriteLine(site.Name);
    }
}

如果我直接把这些代码在一个控制台应用程序,运行它,它会并列出IIS快递网站。如果我运行提升的命令提示符的应用程序,它会列出IIS7网站。有点不方便,但到目前为止那么好。

If I put that code directly in a console application and run it, it will get and list the IIS express websites. If I run that app from an elevated command prompt, it will list the IIS7 websites. A little inconvenient, but so far so good.

如果不是我把代码中所引用和控制台应用程序称为一个类库,它总是会列出IIS快递的网站,即使控制台应用程序是升高的。

If instead I put that code in a class library that is referenced and called by the console app, it will ALWAYS list the IIS Express sites, even if the console app is elevated.

谷歌已经使我尝试以下,没有运气。

Google has led me to try the following, with no luck.

//This returns IIS express
var mgr = new ServerManager();
//This returns IIS express
var mgr = ServerManager.OpenRemote(Environment.MachineName);
//This throws an exception
var mgr = new  ServerManager(@"%windir%\system32\inetsrv\config\applicationhost.config");



显然我误解了在一个提升过程的运行方式的东西。不应该一切从另一个DLL在提升过程中执行的,即使代码,以提升的权限来运行?显然不是?

Evidently I've misunderstood something in the way an "elevated" process runs. Shouldn't everything executing in an elevated process, even code from another dll, be run with elevated rights? Evidently not?

感谢您的帮助!

推荐答案

确认要添加引用到正确的Microsoft.Web.Administration,应该是v7.0.0.0是位于C:\windows\system32\inetsrv\
看起来要添加引用到IIS快递的Microsoft.Web.Administraiton它会给你这种行为

Make sure you are adding the reference to the correct Microsoft.Web.Administration, should be v7.0.0.0 that is located under c:\windows\system32\inetsrv\ It looks like you are adding a reference to IIS Express's Microsoft.Web.Administraiton which will give you that behavior

这篇关于如何使用ServerManager的阅读IIS站点,不是IIS快递,从类库或如何提升进程处理类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆