Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoginStatus for ASP.Net MVC?

How do I get the LoginStatus for ASP.Net MVC? I can connect and authenticate on MVC, but I am not sure how to get the LoginStatus, can anyone help?

like image 588
PlayKid Avatar asked Feb 28 '23 22:02

PlayKid


1 Answers

When you create a new MVC project, the csproj template creates a partial view called "LoginUserControl", located at ~/Views/Shared/LoginUserControl.ascx.

This view has the following logic, which renders different text depending on whether or not the current user is logged in:

<%
    if (Request.IsAuthenticated) {
%>
        Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
        [ <%= Html.ActionLink("Logout", "Logout", "Account") %> ]
<%
    }
    else {
%> 
        [ <%= Html.ActionLink("Login", "Login", "Account") %> ]
<%
    }
%>
like image 157
Portman Avatar answered Mar 11 '23 09:03

Portman