[英]How to authenticate user without login
是否可以仅使用UserId在标准ASP .NET MVC4项目下验证用户,以便我们可以跳过下面的代码?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
好的,这是解决方案
var userId = "123";
using (UsersContext db = new UsersContext())
{
UserProfile userProfile = db.UserProfiles.FirstOrDefault(u => u.UserId == userId);
FormsAuthentication.SetAuthCookie(userProfile.UserName, false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.