2015-10-25 10 views
6

में साइन इन नहीं कर रहा है मैं डेटाबेस से वैध उपयोगकर्ता प्राप्त कर सकता हूं, ClaimsIdentity और 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(); 
} 
हालांकि

, जब मैं जाँच करता है, तो उपयोगकर्ता इस तरह दृश्य पर प्रवेश किया गया है:

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

IsAuthenticated रिटर्न false

उत्तर

7

मैं Owin स्टार्टअप वर्ग से AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie याद आ रही थी:

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

appBuilder.UseCookieAuthentication(authenticationOptions); 

यह वहाँ एक अच्छा, उपयोगी त्रुटि नहीं है कि शर्म की बात है। मुझे उन कार्यक्रमों को पसंद नहीं है जो चुपचाप असफल हो जाते हैं।

संबंधित मुद्दे