2017-09-18 3 views
0

Ich habe HomeController, welche Index-Methode haben [Autorisieren], also wenn nicht Login als Redirect zu Login-Aktion und nach erfolgreicher Anmeldung es umleiten zu Patient Home Controller.Aber Problem ist Authentifizierung ist funktioniert nicht.Wie man Authentifizierung in asp.Net MVC 5

[Authorize] 
    [HttpGet] 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    [HttpGet] 
    public ActionResult Login() 
    { 
     return View(); 
    } 
    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult Login(User user) 
    { 
     User usr = _logingService.Login(user.Email,user.Password); 
     if(usr!=null) 
     { 
      Patient pat = _patientService.GetPatient(usr.Id); 
      FormsAuthentication.SetAuthCookie(pat.Name, false); 
      if (usr.Role == "Patient") 
      { 

       return RedirectToAction("Index", "Home", new { Area = "Patient" }); 
      } 
      else 
      { 
      } 

     } 

     return View(); 
    } 

nun aus der Datenbank I Istwert bin immer aber nach, wenn es umleiten Index Aktion Patienten, da habe ich wieder [autorisieren], aber es umleiten wieder zur Login-Seite

[Authorize] 
    [HttpGet] 
    public ActionResult Index() 
    { 
     return View(); 
    } 
+0

Siehe hier - haben Sie das 'FormsAuthenticationModule' aus Ihrer web.config entfernt? https://stackoverflow.com/questions/26613421/formsauthentication-setauthcookie-doesnt-authorize-in-mvc-5 –

+0

Danke Sir jetzt seine Arbeit –

Antwort

0

von web.config entfernen:

<modules> 
    <!--<remove name="FormsAuthenticationModule" />--> 
</modules> 

oder einfach entfernen Sie die Zeile in web.config und es wird gut funktionieren.