【问题标题】:Asp.net core 3.1 windows authentication and authorization similar to asp.net 4.x web.config rolesAsp.net core 3.1 windows 身份验证和授权类似于 asp.net 4.x web.config 角色
【发布时间】:2020-07-08 19:18:59
【问题描述】:

我正在将旧的 asp.net 4.x 站点转换为 asp.net core 3.1。旧站点使用 web.config 和使用本地计算机用户组而不是 AD 组的角色。我似乎找不到在 .net 核心中实现这一点的简单方法,我已经打了几篇文章并尝试过,但没有成功。

所以这里是之前的asp.net 4.x web.config的一个例子

  <location path="reporting">
    <system.web>
      <authorization>
        <allow roles=".\team_reporting" />
        <allow roles=".\team_admins" />
        <allow roles=".\sites_admins" />
      </authorization>
    </system.web>
  </location>

因此“reporting”路径或目录定义了 3 个不同的本地 Windows 组,称为“team_reporting”、“team_admins”和“sites_admins”。这些本地组将具有 AD 用户帐户。因此,如果活动目录帐户“ad_domain\john”访问了该站点,如果他在 3 个组中的任何一个中,他就可以访问报告目录。

我试过这个方法对我不起作用 https://ianvink.wordpress.com/2018/06/06/asp-net-core-2-quick-and-dirty-windows-authentication/ 和其他一些人。

我已经能够在 asp.net 核心中获取 AD 用户的 AD 名称/ID,但只是在寻找如何使用在 Windows 本地组中配置的 AD 用户 ID 在 asp.net 核心中实现角色身份验证服务器?

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

    我在这篇文章中找到了一种使用 AD 组的方法,该方法也适用于本地组,我之前尝试过,但它不起作用,但现在可以工作了 :) 我还解释了为什么当我不工作时它不起作用以前试过。

    https://forums.asp.net/t/2152453.aspx

    也使用“.\local_group_name”不起作用,所以我必须使用服务器名称“webserver\local_group_name”才能使其工作。在以前的 asp.net 4.x 中,我可以使用 .\ 很好。所以当我第一次在我的 Startup.cs 文件中尝试这个解决方案时,我在 UseAuthentication 之前有 UseAuthorization

    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseRouting();
    app.UseAuthorization();
    app.UseAuthentication();
    

    在授权之前放置 Auth 后它起作用了 :)

    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 2018-09-06
      • 2019-04-30
      相关资源
      最近更新 更多