简体   繁体   English

Intranet站点的ASP.NET身份+ Windows身份验证

[英]ASP.NET Identity + Windows Authentication for Intranet Site

I am building an intranet site where users will be on the corporate domain and have different permission levels. 我正在构建一个Intranet站点,其中用户将在公司域上并具有不同的权限级别。 I'm currently using <authentication mode="Windows"/> to control site access, but it seems like I should be using ASP.NET Identity . 我目前正在使用<authentication mode="Windows"/>来控制站点访问,但似乎我应该使用ASP.NET身份

For example, say my application is a dashboard for each department in the organization. 例如,假设我的应用程序是组织中每个部门的仪表板。 I want to create a single AD group called DashboardUsers and put everyone that can touch the site in this group. 我想创建一个名为DashboardUsers AD组,并将每个可以触及该组中的站点的人放入。

I also want to restrict the views in the dashboard. 我还想限制仪表板中的视图。 For example, I only want the IT group to see their view, and the Finance folks see theirs, etc. 例如,我只希望IT小组看到他们的观点,财务人员看到他们的观点等。

Question -- should I be using Windows Authentication to control access to the site, and then use ASP.NET Identity for user level permissions? 问题 - 我应该使用Windows身份验证来控制对站点的访问,然后使用ASP.NET身份进行用户级权限吗?

I have done something similar to this using only WindowsAuthentication. 我只使用WindowsAuthentication做了类似的事情。 You can tag your actions with the Authorize Attribute: 您可以使用授权属性标记您的操作:

[Authorize(Roles = @"DashboardUsers")]

As long is this user is a member of the DashboardUsers AD group they will get access to this action. 只要此用户是DashboardUsers AD组的成员,他们就可以访问此操作。 It seems like MVC magic, but it really is that simple. 它看起来像MVC魔术,但它真的很简单。

Unfortunately this approach will not allow you to overload an action for different Roles as the Authorize Attribute is not part of the method's signature. 不幸的是,这种方法不允许您为不同的角色重载动作,因为授权属性不是方法签名的一部分。 In your views, you would have to show different anchor tags based on the current users role. 在您的视图中,您必须根据当前用户角色显示不同的锚标记。

ie: 即:

[Authorize(Roles = @"DashboardUsers\Manager")]
public ActionResult IndexManagers()
{
..
}

or 要么

[Authorize(Roles = @"DashboardUsers\Finance")]
public ActionResult IndexFinance()
{
..
}

EDIT AFTER COMMENT: Since your Identity is coming from AD, you could use logic in your controller like: 编辑后编辑:由于您的身份来自AD,您可以在控制器中使用逻辑,如:

if(User.IsInRole("Finance"))
{
..
}
else if(User.IsInRole("IT"))
{
..
}

And this will check which AD Group they belong too. 这将检查他们属于哪个AD组。 I know it's not very elegant, but I can't imagine mixing Windows Auth with a custom identity and managing permissions in your own db would be elegant either. 我知道它不是很优雅,但我无法想象将Windows Auth与自定义标识混合在一起,并且在您自己的数据库中管理权限也会很优雅。

I have run into this dilemma before and wound up creating a custom role provider that i used in conjunction with windows authentication. 我之前遇到过这种困境,并且创建了一个与Windows身份验证结合使用的自定义角色提供程序。 I'm not sure you need the OWIN middleware when authenticating against AD. 在对AD进行身份验证时,我不确定您是否需要OWIN中间件。

public class MyAwesomeRoleProvider : RoleProvider
{
    public override void AddUsersToRoles(string[] usernames, string[] roleNames)
    {
        // i talk to my database via entityframework in here to add a user to a role.
    }

    // override all the methods for your own role provider
}

config file 配置文件

<system.web>
    <authentication mode="Windows" />
    <roleManager enabled="true" defaultProvider="MyAwesomeRoleManager">
      <providers>
        <clear />
        <add name="MyAwesomeRoleManager" type="MyAwesomeNamespace.MyAwesomeRoleProvider" connectionStringName="MyAwesomeContext" applicationName="MyAwesomeApplication" />
      </providers>
    </roleManager>
</system.web>

暂无
暂无

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

相关问题 Windows身份验证Intranet和ASP.NET身份MVC网站之间的安全集成 - Security Integration between Windows Authentication Intranet and ASP.NET Identity MVC Website 在ASP.NET MVC中使用自定义登录页面进行Intranet Windows身份验证 - intranet windows authentication with with custom login page in ASP.NET MVC 使用 Windows 身份验证的 ASP.NET Core 标识 - ASP.NET Core Identity with Windows Authentication ASP.NET MVC3内联网站点 - ASP.NET MVC3 Intranet Site 适用于 Windows-Identity 的 Asp.Net Core Intr.net 应用程序中的模拟中间件 - Impersonation Middleware in an Asp.Net Core Intranet app for Windows-Identity 为ASP.NET MVC Intranet应用程序实施Windows身份验证的最佳方法是什么? - What's the best way to implement Windows Authentication for an ASP.NET MVC intranet application? 在ASP.Net MVC应用程序中将身份验证从个人帐户更改为Windows(Intranet) - Changing Authentication from individual accounts to Windows (Intranet) in ASP.Net MVC app 如何使用基本身份验证来访问从Windows服务使用Windows身份验证的Asp.Net MVC 4 Intranet Web API方法? - How to use Basic Authentication to access Asp.Net MVC 4 Intranet Web API method which uses Windows Authentication from a Windows Service? ASP.NET MVC 4:身份验证和授权:Intranet应用程序 - ASP.NET MVC 4 : Authentication and Authorization:Intranet Application Intranet ASP.NET应用程序模拟和数据库身份验证 - Intranet ASP.NET Application Impersonation and Database Authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM