2017-09-18 11 views
0

私はIndexメソッドに[Authorize]があるHomeControllerを持っているので、ログインアクションにリダイレクトするよりもログインしていない場合は、ログイン後にPatient Homeコントローラにリダイレクトします。働いていない。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(); 
    } 

これで、データベースから、私は実際の値を取得していますが、それはindexアクションを患者にリダイレクトするとした後、そこに私は再び[承認]を使用しますが、それはweb.configファイルからページ

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

ここをクリックしてください。あなたのweb.configから 'FormsAuthenticationModule'を削除しましたか? https://stackoverflow.com/questions/26613421/formsauthentication-setauthcookie-doesnt-authorize-in-mvc-5 –

+0

ありがとうございます –

答えて

0

ログインするために再びリダイレクト削除:

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

またはsimplesでweb.configの行を削除しても問題ありません。

関連する問題