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

asp.net MvcUser Controls

asp.net Mvc Problem Overview


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

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

Does this work?

<%= Page.User.Identity.IsAuthenticated %>

Solution 2 - asp.net Mvc

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

@Request.IsAuthenticated

Solution 3 - asp.net Mvc

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

Solution 4 - asp.net Mvc

Well I use VB

If User.Identity.Name = "" Then
   Response.Redirect("~/Login.aspx")
Else
   ........continue...........
End If

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHannoun YassirView Question on Stackoverflow
Solution 1 - asp.net MvcgriegsView Answer on Stackoverflow
Solution 2 - asp.net MvcDan AtkinsonView Answer on Stackoverflow
Solution 3 - asp.net MvcCmdrTallenView Answer on Stackoverflow
Solution 4 - asp.net MvcEshanView Answer on Stackoverflow