views:

2318

answers:

3

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

+5  A: 

Does this work?

<%= Page.User.Identity.IsAuthenticated %>
griegs
+9  A: 

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

<% Request.IsAuthenticated %>

Dan Atkinson
+3  A: 

You could decorate the Method with the Authorize attribute. This requires that the User calling the Method being authenticated.

CmdrTallen