on-internet
← Community

How should I check if a user is authenticated in ASP.NET MVC 5?

Stack Overflow ·

I have seen the following two accessible Booleans: System.Web.Mvc.Controller.User.Identity.IsAuthenticated System.Web.Mvc.Controller.Request.IsAuthenticated Is there a difference between these. They both seem to do the same thing so I am not sure which to use. What I would like to do is: @if (User.Identity.IsAuthenticated) { if (User.IsInRole("Admin")) { @Html.ActionLink("Admin", "AdminController") } } or @if (Request.IsAuthenticated) { if (User.IsInRole("Admin")) { @Html.ActionLink("Admin", "AdminController") } } Would either of the above work equally well?

Comments

Sign in or sign up to comment and upvote.

No comments yet.