make a button to terminate user session (asp)?

0

I'm developing a site that allows the user to log in to his account and such, but I need q after he logs that login button sum and one appears 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>
    
asked by anonymous 14.10.2016 / 15:42

1 answer

2

Do not make up the wheel! Rule number 1 of system development: -)

Use the LoginView control that already implements this logic and makes it much easier. Here's an idea, based on the piece of code you provided, how your final code looks . 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 for authenticated (logged in) users. This is exactly what you intend to do manually ( O OnLogginOut may not need to be handled in your code ).

Read more about the control here: LoginView class

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

    
14.10.2016 / 17:53