Question

just as the title says, how do you properly implement/simulate the Logout function in asp:Login to a siteMapNode?

<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                <AnonymousTemplate>
                    <%--[ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]--%>
                    [ <a href="~/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                </AnonymousTemplate>
                <LoggedInTemplate>
                    Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                    [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/Login.aspx"/> ]
                </LoggedInTemplate>
            </asp:LoginView>

the best I could do is this:

<siteMapNode url="~/Login.aspx" title="Logout" roles="Maker, Admin, Approver" description="" />

but this only redirects the user to the Login page. When you press the Back button on the web browser, the user is still logged in to the system, unlike when you use the proper Logout function.

Was it helpful?

Solution

You could add a Logout.aspx page, which terminates the user's session and then redirects to the login page, e.g:

Session.Abandon();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

Your siteMapNode should then refer to the logout page.

OTHER TIPS

You need check this below condition in inside of page load event in your all user pages

If(!User.Identity.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}

Now if you logout, then come this page form using browser back button or url . that code was allowed if your loggin else it's going to login page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top