How should I check if a user is authenticated in MVC5?

前端 未结 3 853
我在风中等你
我在风中等你 2021-01-30 20:33

I have seen the following two accessible booleans:

  • System.Web.Mvc.Controller.User.Identity.IsAuthenticated
  • System.Web.Mvc.Controller.Re
3条回答
  •  面向向阳花
    2021-01-30 21:01

    Based On Darin Dimitrov's Answer, You can shorten the code and use in place:

    if( User?.Identity != null && User.Identity.IsAuthenticated )
    { 
    //Code Goes Here!
    }
    

提交回复
热议问题