【问题标题】:Programmatically set IIS Authentication model for a specific asp.net file以编程方式为特定的 asp.net 文件设置 IIS 身份验证模型
【发布时间】:2011-12-22 04:40:06
【问题描述】:

我需要在我的 IIS Web 服务应用程序中设置特定 asp.net 文件的身份验证模型。主题“如何以编程方式在 .NET Web 服务上的 IIS 中设置集成 Windows 身份验证?”基本上做我想要的,但对于整个网站。我需要拥有除一项网络服务匿名访问之外的所有服务,但需要使用“Windows 身份验证”

像这样:

应用此代码时,我无法弄清楚如何指定某个文件:

String applicationPath = String.Format("{0}/{1}", _server.Sites["Default Web Site"].Name, "AppName"); 

Configuration config = _server.GetApplicationHostConfiguration(); 

ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", applicationPath); 

anonymousAuthenticationSection["enabled"] = false; 

ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", applicationPath); 

windowsAuthenticationSection["enabled"] = true; 

_server.CommitChanges(); 

【问题讨论】:

    标签: asp.net iis


    【解决方案1】:

    您可以使用 web.config 文件的位置节点来配置应用程序的特定目录/文件。或者,如果您不想弄乱根 web.config,您可以在子目录中创建额外的 web.config 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      相关资源
      最近更新 更多