Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if user is logged in in user control Asp.net MVC

how can i check if a user is logged in in user control with asp.net mvc

usually on a view page i use this

<% if (User.Identity.IsAuthenticated) {%>   //Do something <% } %> 

but i can't get this done on a user control

like image 646
Hannoun Yassir Avatar asked Aug 26 '09 02:08

Hannoun Yassir


People also ask

How can get current logged in user in ASP NET MVC?

If you need to get the user from within the controller, use the User property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData , or you could just call User as I think it's a property of ViewPage .


2 Answers

Nothing new to add to Griegs answer, but I would normally do

@Request.IsAuthenticated 
like image 24
Dan Atkinson Avatar answered Oct 17 '22 17:10

Dan Atkinson


Does this work?

<%= Page.User.Identity.IsAuthenticated %> 
like image 100
griegs Avatar answered Oct 17 '22 17:10

griegs