I just want to put LogIn Status text in MY ASP master page. When User not logged IN it will show LogIn and If user already logged In it will show LogOut. Once user Clicked logOut ,session will be clear .
<asp:LoginView ID="LoginView1" runat="server" onviewchanged="LoginView1_ViewChanged">
<AnonymousTemplate>
<asp:LoginStatus ID="LoginStatus1" runat="server" LoginText="logIn" />
</AnonymousTemplate>
<LoggedInTemplate>
<asp:LoginStatus ID="LoginStatus2" runat="server" LogoutText="loggedout" />
</LoggedInTemplate>
</asp:LoginView>
I am using using System.Web.SessionState; to manage session. I can check user is login or not by using bellow code.
If (Session["logged"] == true)
Please help me to display LogIn or logOut Status in Master page in Dynamically according to current session status. Thank you in advance.
LoginViewcontrol uses the current request’s identity to determine whether or not they are logged in, and also the principal’s role memberships, if you use the feature where you can show different templates for different roles. So, you won’t be able to achieve what you wish usingLoginView. Same thing withLoginStatus.You can roll your own versions of those controls to do what you wish, or attempt to derive your own control from those controls and simply override the part where it figures out if you’re logged in or not.
Alternately, you can just place something like this in your master page.
However, I’d recommend you just rely on the request’s identity to determine whether or not a user is logged in. A) it’s built-in, fully supported, and you don’t have to do anything extra B) Sessions are not durable. You can access the request’s user in a page, control, etc. by accessing the
User.Identity.IsAuthenticatedproperty.