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
Does this work?
<%= Page.User.Identity.IsAuthenticated %>
<%= Context.User.Identity.IsAuthenticated %>Nothing new to add to Griegs answer, but I would normally do
@Request.IsAuthenticated
HttpRequestWrapper and then HttpRequest the IsAuthenticated property is implemented with User.Identity.IsAuthenticated, among other things. return(_context.User != null && _context.User.Identity != null && _context.User.Identity.IsAuthenticated);You could decorate the Method with the Authorize attribute. This requires that the User calling the Method being authenticated.
Well I use VB
If User.Identity.Name = "" Then
Response.Redirect("~/Login.aspx")
Else
........continue...........
End If
User, how would this make any difference "in a user control". Your example is in a controller and not a user-control. -1