简体   繁体   English

ASP.NET活动目录身份验证User.IsInRole

[英]ASP.NET active directory authentication User.IsInRole

I developed an ASP.NET Intranet application. 我开发了一个ASP.NET Intranet应用程序。 Now I was asked to add authentication for the application - it should be based on Active Directory. 现在,我被要求为应用程序添加身份验证-它应该基于Active Directory。 The user should not fill in any login or password. 用户不应填写任何登录名或密码。

From within ASP.NET C# code I should be able to check something like this: 从ASP.NET C#代码中,我应该能够检查如下内容:

if (User.IsInRole("MyApplicationReaders"))
{
     doSomething();
}
else if (User.IsInRole("MyApplicationAdmins"))
{
     doSomethingElse();
}

MyApplicationReaders and MyApplicationAdmins are names of Active Directory groups. MyApplicationReaders和MyApplicationAdmins是Active Directory组的名称。

Can you please point me to some easy step-by-step tutorial how to achieve this? 您能否指点我一些简单的分步教程来实现这一目标? I failed to find any :-( 我找不到任何:-(

Try to search harder. 努力搜索。

You have to add to configuration file authentication method: 您必须向配置文件添加身份验证方法:

<authentication mode="Windows" />

And also add authorization rules: 并添加授权规则:

<authorization>
  <allow users="DomainName\Bob, DomainName\Mary" />
  <allow roles="BUILTIN\Administrators, DomainName\Manager" />
  <deny users="*" />
</authorization>

This this page for help. 页面寻求帮助。

PS: After you'll add windows authentication to your app you will be able to check User.IsInRole for authenticated users. PS:将Windows身份验证添加到您的应用程序后,您将能够检查User.IsInRole是否有已身份验证的用户。 But in some browsers your users will be promted to enter their's windows credentials. 但是在某些浏览器中,系统将提示您输入用户的Windows凭据。

You can set IIS to authenticate users automatically, but typically you implement your own authorization scheme. 您可以将IIS设置为自动对用户进行身份验证,但是通常可以实现自己的授权方案。 In the past, I have used a database to map my AD accounts to application roles/permissions. 过去,我曾使用数据库将我的AD帐户映射到应用程序角色/权限。

In order to use the IsInRole(), you have to populate the User Principal object. 为了使用IsInRole(),必须填充User Principal对象。 The easiest place to do that is in the Global.asax event BeginRequest . 最简单的方法是在Global.asax事件BeginRequest中 Also take a look at creating a Custom Role Provider . 另请参阅创建自定义角色提供程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM