我正在尝试使用此代码(来自同一服务器上的其他站点)在IIS中创建一个网站
using Microsoft.Web.Administration;
//...
ServerManager manager = new ServerManager();
manager.Sites.Add(Host, "http", ":80:" + Host, Path);
//...
但我得到了这个例外:
MESSAGE:文件名:redirection.config 错误:由于权限不足,无法读取配置文件
我尝试过这样的假冒:http://www.codeproject.com/KB/cs/zetaimpersonator.aspx 但后来我得到了一个丑陋的COM错误。
模仿正确用户的最佳方式是什么,或指定用户来管理经理。
答案 0 :(得分:4)
要使用ServerManager
API,您需要成为正在管理的计算机上的本地管理员。当您的代码在IIS应用程序的上下文中运行时,您需要将此应用程序的应用程序池标识更改为管理用户(IIS 7.x上的默认标识为ApplicationPoolIdentity
,这是一个非特权用户)。
或者,您可以通过将这些元素添加到Web.config中的<system.web>
部分来启用ASP.NET模拟:
<authentication mode="Windows" />
<identity impersonate="true" />
...并为IIS应用程序启用Windows Authentication
。但通常不建议这样做(参见:http://www.hanselman.com/blog/AvoidUsingImpersonationInASPNET.aspx)。
答案 1 :(得分:0)
可能是您的IISExpress文件夹是由您的用户编写的,如果您以管理员身份打开Visual,则无权访问该文件......
C:\ Users :: your user :: \ Documents \ IISExpress \ config
然后再试一次......它对我有用。