首页 文章

使用没有Idenity的Owin

提问于
浏览
0

我有一个asp mvc应用程序,需要非常低级别的身份验证和登录功能 . 用户具有唯一的7位数字,他们将在其中输入以登录应用程序 . 经过身份验证后,他们可以编辑EF数据库 . 而已!

目前我正在使用Owin的基本实现来验证和登录用户 . 基本上我有一个输入字段,用户输入他们的号码,然后我使用EF查找,如果我找到我创建索赔的号码并签名 .

我是新手,我没有看到使用Asp Identity系统的好处,因为我不需要外部登录功能或注册功能 . 另外,我没有用户 Profiles . 我只需要一种方法来检查这些数字,以确定用户是否在DB中,然后对其进行签名 . 所以问题是:我的实现只有Owin有效吗?为什么我需要asp身份框架呢?

[HttpPost, AllowAnonymous, ValidateInput(true)]
        public ActionResult Index(employeePSDB lookUpEmployeeID)
        {
            if (ModelState.IsValid)
            {
                using (var db = new PsEntities())
                {
                    IEnumerable<employeePSDB> foundEmployeeInDb = db.employeePSDBs.Where(foundEmployee => lookUpEmployeeID.EmployeeNumber == foundEmployee.EmployeeNumber);


                    if (foundEmployeeInDb.Count() > 0)
                    {
                        var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Name, foundEmployeeInDb.First().EmployeeNumber.ToString())
                        }, "ApplicationCookie");

                        var contex = Request.GetOwinContext();
                        var authManager = contex.Authentication;



                        authManager.SignIn(identity);
                        return Redirect(GetRedirectUrl(lookUpEmployeeID.ReturnUrl));
                    }
                }
            }
  //user authN failed or ModelState is not valid
        ModelState.AddModelError("", "Not in db");
        employeePSDB newLookUp = new employeePSDB
        {
            ReturnUrl = lookUpEmployeeID.ReturnUrl
        };
        return View(newLookUp);
    }

1 回答

相关问题