【发布时间】:2020-02-21 05:30:33
【问题描述】:
我的网站是通过桌面 (Silverlight) 应用程序管理数据的在线门户。此应用程序使用基于 ASP.NET 表单的身份验证来登录用户。
我的网站的 MVC Core 1.1 版本使用来自 System.Web.Security 命名空间的 MembershipProvider.ValidateUser 来执行此操作。由于我无法将System.Web.dll 添加到我的 ASP.NET MVC 2.0 项目中,我该如何执行此验证?
如果我在添加System.Web.dll 时有误,请告知我,但我已经调查过了,找不到解决方案。
我的 MVC Core 1.1 控制器中的登录方法:
[HttpPost]
[AllowAnonymous]
public IActionResult Login(LoginViewModel vmLogin)
{
string loginName = $"{vmLogin.CompanyCode}\\{vmLogin.UserName}";
MembershipProvider provider = Membership.Provider;
if (provider.ValidateUser(loginName, vmLogin.Password))
{
Claim[] claims = { new Claim(ClaimTypes.Name, loginName) };
ClaimsIdentity identity = new ClaimsIdentity(claims, "Custom");
ClaimsPrincipal principal = new ClaimsPrincipal(identity);
HttpContext.Authentication.SignInAsync("FundraiserCookieMiddlewareInstance", principal);
return RedirectToAction("Index");
}
else
{
vmLogin.Password = string.Empty;
vmLogin.Error = "Invalid Credentials";
return View(vmLogin);
}
}
【问题讨论】:
-
你说得对,
System.Web程序集在 ASP.NET Core 中不可用。它仅适用于完整的 .NET Framework 版本。
标签: c# asp.net-core asp.net-core-2.0