【发布时间】:2014-06-22 14:29:50
【问题描述】:
这是我的问题http://screencast.com/t/v6th4BuRLhV的视频摘要
我正在尝试使用以下代码以编程方式将绑定添加到 IIS:
public void AddBindings(string sitename, string hostname)
{
ServerManager serverMgr = new ServerManager();
Site mySite = serverMgr.Sites[sitename];
mySite.Bindings.Add("*:80:" + hostname, "http");
mySite.ServerAutoStart = true;
serverMgr.CommitChanges();
}
我得到这个错误:
Filename: redirection.config
Error: Cannot read configuration file due to insufficient permissions
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Filename: redirection.config
Error: Cannot read configuration file due to insufficient permissions
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
我已经解决了redirection.config的权限(IUSR和IIS_IUSRS都有权限)
以及此处建议的 web.config 上的错误http://www.codeproject.com/Questions/348972/Error-Cannot-read-configuration-file-due-to-insuff
但还是不行。
回答
网站不在 IIS 组下运行。拥有应用程序池的人就是用户,这是需要许可的用户。或者将该用户放在 IIS_IUSRS 组中。
【问题讨论】:
-
你什么时候执行你的代码?它是部署脚本(即 msbuild)的一部分吗?
-
它是 MVC 应用程序的一部分。这是一个视频,向您展示发生了什么screencast.com/t/v6th4BuRLhV
-
@Petras 你好,你找到解决方案了吗?这让我发疯了
-
上面的答案涵盖了它。它太久远了,我记不起其他的了!