![](/img/trans.png)
[英]How do i Authenticate and register users from the business Logic Layer with ASP.NET Core 3.1 Identity
[英]How do I authenticate user in ASP.NET Identity framework?
我正在使用默认的ASP.NET 4.5框架的ASP.NET MVC 5项目模板。 它具有配置的身份验证框架。
我想在我的项目中使用Window的Active Directory,所以我遵循了这篇文章-http: //www.schiffhauer.com/mvc-5-and-active-directory-authentication/
在我的AccountController的登录方法中,
if (Membership.ValidateUser(model.Email, model.Password))
{
CustomFormsAuthentication.SetAuthenticationCookie(model.Email, model, model.RememberMe);
return RedirectToAction("Index", "Home");
}
其中CustomFormsAuthentication类具有
public static class CustomFormsAuthentication
{
public static void SetAuthenticationCookie(string username, object obj, bool isPersistent)
{
const int version = 1;
var json = new JavaScriptSerializer().Serialize(obj);
var cookieStoreTime = isPersistent ? DateTime.Now.AddDays(7): DateTime.Now.AddDays(1);
var ticket = new FormsAuthenticationTicket(version, username, DateTime.Now, cookieStoreTime, isPersistent, json);
HttpContext.Current.Response.Cookies.Set(new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(ticket)) {Expires = cookieStoreTime});
}
}
但是用户永远不会被认证。 User.Identity.IsAuthenticated仍显示为false。
我该怎么办?
身份与表单身份验证不兼容(由代码中的ASP.NET成员资格使用)。 即使这样,表单身份验证也与Windows身份验证不兼容,Windows身份验证也与Identity不兼容。 如果要使用Windows凭据进行身份验证,则需要将Web.config更改为具有:
...
<system.web>
...
<authentication mode="Windows"/>
...
</system.web>
...
然后您几乎可以删除所有Identity内容,因为它将不再起作用。
编辑
在注释中进行讨论之后,此处最重要的一点是,ASP.NET不支持同时进行多种形式的身份验证。 从技术上讲,您可以执行一些变通办法,以便基本上将身份验证代理到LDAP服务器,以验证AD凭据,然后基于该身份创建/获取一个身份/会员身份用户,使其成为经过身份验证的用户。
但是,在这里,我没有看到任何真正的尝试,即使如此,您仍在使用ASP.NET成员资格和表单auth来处理它,从而无法使用Identity。 身份和表单auth完全不兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.