2015-10-25 13 views
6

'da oturum açmıyor Geçerli kullanıcı veritabanından alabilir, ClaimsIdentity'u oluşturabilir ve SignIn yöntemi hatasız olarak çağrılabilir. AncakAuthenticationManager.SignIn(),

public ActionResult SignInConformation(SignInModel model) 
{ 
    if (ModelState.IsValid) 
    { 
     var user = _userManager.Find(model.Username, model.Password); 

     if (user == null) 
     { 
      ModelState.AddModelError("", "Invalid username and\\or password"); 
     } 
     else 
     { 
      _authenticationManager.SignOut(); 
      var claimsIdentity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); 
      _authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claimsIdentity); 
      return RedirectToAction("Index", "Home"); 
     } 
    } 

    return View(); 
} 

, kullanıcı böyle görünüme oturum açmışsa ben kontrol edin:

<p> 
    Current User: @if (User.Identity.IsAuthenticated) 
        { 
         @User.Identity.Name 
        } 
        else 
        { 
         @:Unknown 
        } 
</p> 

IsAuthenticated döner false.

cevap

7

Ben Owin başlangıç ​​sınıfından AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie eksikti:

var authenticationOptions = new CookieAuthenticationOptions 
{ 
    LoginPath = new PathString("/Account/SignIn"), 
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie 
}; 

appBuilder.UseCookieAuthentication(authenticationOptions); 

Bu güzel, faydalı hata olmadığını utanç vericidir. Sessizce başarısız olan programları sevmiyorum.