【问题标题】:Cant add bindings to IIS programmatically - redirection.config permissions (with a video!)无法以编程方式将绑定添加到 IIS - redirection.config 权限(带视频!)
【发布时间】: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 你好,你找到解决方案了吗?这让我发疯了
  • 上面的答案涵盖了它。它太久远了,我记不起其他的了!

标签: asp.net iis binding


【解决方案1】:

找出您的应用程序池以哪个帐户运行。然后,您需要授予该帐户对整个 %SystemRoot%\System32\inetsrv\config 文件夹的访问权限。我只提供%SystemRoot%\System32\inetsrv\config\redirection.config的访问权限是不够的

【讨论】:

  • 我的团队中有人这样做了。我们的 netcore5.0 应用程序运行良好,即使在对 %SystemRoot%\System32\inetsrv\config 文件夹中的每个文件应用新权限时弹出一些错误。
【解决方案2】:

在我的情况下,“以管理员身份运行”解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多