如何以编程方式使用ServerManager允许IIS管理器用户访问IIS站点 [英] How to Allow IIS Manager User to a IIS Site using ServerManager Programatically

查看:102
本文介绍了如何以编程方式使用ServerManager允许IIS管理器用户访问IIS站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许现有的IIS管理器用户使用C#进入IIS站点或网站.

I would like to Allow the Existing IIS Manager User to a IIS Site or Website Using C# .

任何人都可以共享示例代码.这真的很有帮助.

anyone can share the sample code . It would be really helpful .

查看图片我要以编程方式添加这些用户.

Look at the image I want to add those users programmatically .

谢谢,贾斯旺斯

推荐答案

我的建议是不要使用ServerManager来做到这一点,尽管可以通过配置API来实现,但是您将不会尊重IIS用户支持的提供程序模型.例如,某人可能有一个"SQL Server"数据库提供程序,然后您在config中的用户确实无法工作.

My recommendation would be not to do that using ServerManager, although possible through config APIs, you would not be respecting the provider model that IIS Users support. For example someone could have a "SQL Server" database provider and then your users in config really would not work.

要正确执行此操作,请在Microsoft.Web.Management.dll(在Windows \ system32 \ inetsrv)文件夹中使用一个名为ManagementAuthentication的API,该API为此提供了两种方法:CreateUser和Grant.

To do that properly you use an API in Microsoft.Web.Management.dll (in windows\system32\inetsrv) folder, called ManagementAuthentication which has two methods for that: CreateUser, and Grant.

几年前,我写了一篇博客文章,介绍如何从PowerShell调用它们: http://blogs.msdn.com/b/carlosag/archive/2009/10/23/adding-iis-manager-users-and-permissions-through-powershell.aspx

I wrote a blog entry a few years ago on how to call them from PowerShell: http://blogs.msdn.com/b/carlosag/archive/2009/10/23/adding-iis-manager-users-and-permissions-through-powershell.aspx

但是调用它们就像:

Microsoft.Web.Management.Server.ManagementAuthentication.CreateUser("MyUser", "ThePassword");
Microsoft.Web.Management.Server.ManagementAuthorization.Grant("MyUser", "Default Web Site", false); 

这将正确使用配置的任何提供程序,并且如果使用默认配置提供程序,则将其保存在Administration.config中,但是如果在其他位置,它将做正确的事情(例如,将数据插入到数据库或其他地方).

This will correctly use whichever provider is configured, and if the default configuration provider is used then that will save it in Administration.config, but if it was somewhere else it would do the right thing (such as inserting the data in a database or elsewhere).

这篇关于如何以编程方式使用ServerManager允许IIS管理器用户访问IIS站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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