views:

267

answers:

1

Hi There,

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?

Thanks

+4  A: 

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") %> ]
<%
    }
%>
Portman
Yes, thanks alot, that's what I am looking for.
PlayKid
One could argue that there is too much logic in this partial view, just for the if/else portion. I've thought about having two different partial views for this, and let the controller "do its job".
eduncan911