编程方式启用或禁用IIS匿名身份验证 [英] Programmatically enable or disable anonymous authentication in IIS

查看:246
本文介绍了编程方式启用或禁用IIS匿名身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,我需要提供其用户从FormsAuth切换登录方法WindowsAuth的选项。我设法改变通过code中的web.config文件:

I have a web application and I need to provide its users the option to switch login method from FormsAuth to WindowsAuth. I managed to change the web.config file via code:

Configuration config = WebConfigurationManager.OpenWebConfiguration(Url.Content("~"));
AuthenticationSection auth = ((AuthenticationSection)(config.SectionGroups["system.web"].Sections["authentication"]));
auth.Mode = AuthenticationMode.Windows; // Or Forms if I want to.
config.Save();

但问题是,当我使用FormsAuth,我需要的匿名者的身份验证选项被打开,当我使用WinAuth,我需要它关闭。而我只是无法找到改变通过code该选项的方式。

But the problem is, when I use FormsAuth, I need the Anonymouse Authentication option to be turned on, and when I use WinAuth, I need it to be off. And I just cannot find the way to change that option via code.

在互联网上说,一切要做到这一点:

Everything on the internet says to do this:

<security>
 <authentication>
  <anonymousAuthentication enabled="false/true" />
 </authentication>
</security>

但是,当我插入到这一点我的web应用程序的web.config它说配置是错误的。比我读这可能会在其他配置文件的工作,像appHost.config或者类似的东西,但我preFER做出改变只是为了我自己的应用程序,而不是IIS我希望你明白这是为什么。

But when I insert this into my webapp's web.config it says that configuration is wrong. Than I read this might work in another config file, like appHost.config or something like that but I prefer to make changes only to my own application and not to IIS I hope you understand why.

所以,我该怎么办呢?

推荐答案

好了,所以,原来我无法找到一个方法来动态地改变身份验证模式,但我发现pretty很好地解决了这个问题:我创建另一个Web应用程序,嵌套它第一个里面有设置窗体身份验证模式为嵌套第一个和Windows,每当我需要使用IIS的功率域,用户组和工作权,我使用重定向由饼干和URL参数另一个人,传递数据。

Okay, so, turned out I could not find a way to dynamically change the auth mode, but I found pretty neat solution to the problem: I have created another web application, nested it inside the first one, had set Forms Auth mode for the first one and Windows for the nested and whenever I needed to use IIS's power to work with domain, user groups and right, I used a redirect from one to another, passing data by cookies and as url parameters.

这篇关于编程方式启用或禁用IIS匿名身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆