Пример #1
0
        public ActionResult Login(LoginModel model, string ReturnUrl)
        {
            if (ModelState.IsValid)
            {
                //Login işlemleri

                var user = userManager.Find(model.Username, model.Password);

                if (user != null)
                {
                    //Varolan kullanıcı sisteme dahil et
                    // AppCookie oluşturup sisteme bırak.

                    var authManager    = HttpContext.GetOwinContext().Authentication;
                    var identitycalims = userManager.CreateIdentity(user, "ApplicationCookie");
                    var authProperties = new AuthenticationProperties();
                    authProperties.IsPersistent = model.RememberMe;
                    authManager.SignIn(authProperties, identitycalims);

                    var role = user.Roles.ToString();

                    if (!String.IsNullOrEmpty(ReturnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("LoginUserError", "Giriş Başarısız.");
                }
            }


            return(View(model));
        }