自定义 IIdentity - 它在多层应用程序中的位置

本文关键字:应用程序 位置 IIdentity 自定义 | 更新日期: 2023-09-27 17:57:04

给定 3 层架构:

  • 域逻辑层
  • 数据访问层
  • 用户界面层(ASP.NET MVC Web 应用)

放置与构造自定义用户标识、添加自定义声明并将其登录到 Web 应用程序相关的逻辑的正确位置是什么?

例如,这样的逻辑:

if (something)
    customClaim = new Claim("MyClaimType1", "SomeClaimValue");
else
    customClaim = new Claim("MyClaimType2", "AnotherClaimValue");
customClaimsIdentity.AddClaim(customClaim);
HttpContext.Current.GetOwinContext().Authentication.SignIn(customClaimsIdentity);

我想说的是 UI 层,但自定义逻辑(即自定义用户)不是的东西吗? 这里有点困惑...

自定义 IIdentity - 它在多层应用程序中的位置

您描述的是通常与 ASP.NET MVC 相关的安全横切关注点,通常作为操作过滤器实现。基于此,您显示的代码(也直接使用HttpContext)应位于用户界面层(ASP.NET MVC Web 应用程序)中。