make a button to end user session (Asp)?

Asked

Viewed 250 times

0

People I’m developing a site that allows the user to Log into his account and such, but I need q after q he Log this login button to disappear and appear one to end the session (a quit button).

<nav class="acceder">
    <ul>
        <li>
            <asp:Label id="login" runat="server" Text="Entrar">

            </asp:Label>
            <div id="login-content">
                <asp:TextBox ID="txtUser" placeholder="Usuário" runat="server" CssClass="user"></asp:TextBox>
                <asp:TextBox ID="txtPass" placeholder="Senha" runat="server" CssClass="pass" TextMode="Password"> </asp:TextBox>
                <asp:Button ID="btnEntrar" runat="server" Text="Entrar" CssClass="submit" OnClick="btnSubmit_Click" />

            </div>
        </li>
    </ul>
</nav>

1 answer

2

Don’t invent the wheel! Number 1 system development rule :-)

Use the control LoginView that already implements this logic and facilitates a lot. Below an idea, based on the part of code you provided, of how it goes seem your final code. You just need to adapt it to your actual code:

<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
    <AnonymousTemplate>
        <asp:Button ID="btnEntrar" runat="server" Text="Entrar" CssClass="submit" OnClick="btnSubmit_Click" />
    </AnonymousTemplate>
    <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" runat="server" />
        <asp:LoginStatus ID="HeadLoginStatus" runat="server" OnLoggingOut="HeadLoginStatus_LoggingOut"
                LogoutAction="RedirectToLoginPage" LogoutText="Sair" />
    </LoggedInTemplate>
</asp:LoginView>

This control automatically displays a template for anonymous users (not logged in) and authenticated users (logged in). This is exactly what you intend to accomplish manually (The OnLogginOut may not need to be treated in your code).

Read more about control here: Loginview class

To learn more about the ASP.NET login controls that automate these tasks you seem to be doing by hand take a look at: Overview of ASP.NET Login Controls

Browser other questions tagged

You are not signed in. Login or sign up in order to post.