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

前端 未结 4 803
情话喂你
情话喂你 2020-12-29 19:35

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)          


        
相关标签:
4条回答
  • 2020-12-29 19:53

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

    0 讨论(0)
  • 2020-12-29 19:55

    Does this work?

    <%= Page.User.Identity.IsAuthenticated %>
    
    0 讨论(0)
  • 2020-12-29 20:00

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

    @Request.IsAuthenticated
    
    0 讨论(0)
  • 2020-12-29 20:11

    Well I use VB

    If User.Identity.Name = "" Then
       Response.Redirect("~/Login.aspx")
    Else
       ........continue...........
    End If
    
    0 讨论(0)
提交回复
热议问题