简体   繁体   English

如何在不登录的情况下验证用户身份

[英]How to authenticate user without login

Is it possible to authenticate user under the standard ASP .NET MVC4 project using only UserId so we can skip the code below? 是否可以仅使用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))
    {

Ok here is the solution 好的,这是解决方案

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.

相关问题 使用twitter登录验证用户 - Authenticate user with twitter login 如何使用网页加载Google登录按钮对用户进行身份验证? - How to authenticate user with google on page load whitout login button? Microsoft Bot Framework,如何验证用户登录 Web 应用程序 - Microsoft Bot Framework, How to authenticate user to login in web app 如何使用Web API JWT令牌对MVC用户登录表单进行身份验证? - How to authenticate MVC user login form with web API JWT token? c# microsoft graph - 如何在没有登录名和密码的情况下进行身份验证? - c# microsoft graph - how to authenticate without login and password? 如何自动验证Windows集成而无需登录弹出窗口? - How to automatically authenticate windows integrate without login popup? 有没有一种方法可以在不通过 Azure 中的登录页面的情况下对用户进行身份验证(使用一些本地 PC 信息)? - Is there a way to authenticate a user (using some local PC info) without going through login page in Azure? 使用openID进行身份验证,而无需通过提供程序登录 - Authenticate using openID without login through provider 如何在Wamp Server中存储的Xamarin中对用户登录信息进行身份验证 - How can I authenticate user login info in xamarin that is stored in wamp server 网站有/无用户登录 - Website with/without user login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM