使用 Web 管理 C# 在单个服务级别设置 Windows 身份验证Microsoft



需要您指导我目前面临的问题。 我们有一个Web应用程序,它在应用程序的子目录下有一些 asp.net Web服务(asmx(。 每当我们在应用程序级别配置 Windows 身份验证时,我都希望此设置将继承到子目录中的所有 asmx 服务。但他们仍然将其身份验证模式显示为匿名身份验证。 在此状态下,当我尝试访问 Web 服务时,出现 401.2 未授权异常。 我必须手动将服务的身份验证模式更改为 Windows 才能访问该 Web 服务。 我们还尝试使用 Microsoft.Web.Administration dll.我们正在使用

Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection =
config.GetSection("system.webServer/security/authentication/anonymousAuthentication", siteName);

在上面的代码中,siteName 变量包含应用程序的路径,如网站/应用程序 谁能告诉我如何使用ServerManager api在asmx服务级别设置Windows身份验证?

我终于找到了解决这个问题的方法。 应用程序主机配置文件包含每个服务或文件夹的单独条目。因此,如果我们在一个子目录中有多个服务,我们必须为单个服务或子目录提供适当的路径。 所以,代码将是这样的

Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection =
config.GetSection("system.webServer/security/authentication/anonymousAuthentication", siteName);

在上面的示例中,只需将站点名称替换为服务名称或应用程序下任何子目录的路径即可。需要对应用程序下的所有子目录执行此操作。

最新更新