如何将 Active Directory 用于 ASP.Net 5 (MVC6) Intranet 应用程序

How to use active Directory for ASP.Net 5 (MVC6) Intranet application(如何将 Active Directory 用于 ASP.Net 5 (MVC6) Intranet 应用程序)
本文介绍了如何将 Active Directory 用于 ASP.Net 5 (MVC6) Intranet 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发一个 Intranet 应用程序,并希望使用现有组织的 Active Directory 进行用户身份验证和基于策略的角色授权.

I am developing an intranet application and would like to use the existing organisations Active Directory for user authentication and policy based role authorisation.

有人能指出我正确的方向吗?我有点困惑(实际上很困惑).

Can someone point me in the right direction? I am getting a bit confused (well actually a lot confused).

谢谢

推荐答案

http://docs.asp.net/en/latest/security/index.html

首先启动一个新的 ASP.Net Web 应用程序项目,选择 Web 应用程序模板,然后在右侧窗格中按更改身份验证"按钮并选择Windows 身份验证".

First start a new ASP.Net Web Application project, Pick the Web Application template then on the right pane press the "Change Authentication" button and pick "Windows Authentication".

您现在可以在类或方法上使用 [Authorize] 来检查基本身份验证与 RC2 的活动目录,您可以简单地使用组名称 ala [Authorize(Roles=@"域组")]

You can now use [Authorize] on a class or method to check basic authentication vs active directory as of RC2 you can simply use the group names ala [Authorize(Roles=@"DOMAINGROUP")]

现在已经过时且繁琐的替代方案(仍然有效):

The now obsolete and cumbersome alternative (still works):

如果您查看 User.Claims,您可以看到每个用户组的 groupid 键.在此基础上,您可以执行诸如 [Authorize(Policy="FOOBAR")] 之类的操作,并通过

If you look at User.Claims you can see the groupsid keys exist for each of the user's groups. Building off that you can do something like [Authorize(Policy="FOOBAR")] and define it in your Startup.ConfigureServices method via

        services.AddAuthorization(
            o => o.AddPolicy(
                "FOOBAR",
                p => p.RequireClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid",
                    "ENTER GROUP SID")
                ));

请注意,RequireClaim 的第二个参数是一个字符串数组,以允许多个组.

Note that the second param to RequireClaim is a string array to allow for multiple groups.

还要注意通过这个命令行魔法找出组ID dsquery group -name ENTER GROUP NAME" |dsget 组 -sid

Also note to figure out group ids via this command line magic dsquery group -name "ENTER GROUP NAME" | dsget group -sid

这篇关于如何将 Active Directory 用于 ASP.Net 5 (MVC6) Intranet 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

What#39;s the difference between retrieving WindowsPrincipal from WindowsIdentity and Thread.CurrentPrincipal?(从 WindowsIdentity 和 Thread.CurrentPrincipal 检索 WindowsPrincipal 之间有什么区别?)
How do I find a user#39;s Active Directory display name in a C# web application?(如何在 C# Web 应用程序中查找用户的 Active Directory 显示名称?)
How can I authenticate against Active Directory in Nancy?(如何在 Nancy 中对 Active Directory 进行身份验证?)
How to get a username in Active Directory from a display name in C#?(如何从 C# 中的显示名称获取 Active Directory 中的用户名?)
Oauth 2 token for Active Directory accounts(Active Directory 帐户的 Oauth 2 令牌)
Working with DirectoryServices in ASP.NET Core(在 ASP.NET Core 中使用 DirectoryServices)