简体   繁体   中英

How to login with login control and when logged in go to myPage.aspx not Default.aspx in asp.net?

How to login with login control and when logged in go to myPage.aspx not Default.aspx in asp.net?

I want to when logged in go to myPage and give me Information of user.

Login Control has a property DestinationPageUrl . Set your desired page to DestinationPageUrl.

<asp:Login DestinationPageUrl="~/myPage.aspx" ID="LoginUser" runat="server" EnableViewState="false"  RenderOuterTable="false">
        ---------------------
        ---------------------
        ---------------------
</asp:Login>

Also if you want to show userName on your page, you can use HeadLoginView Control Like.

 <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">                   
    <LoggedInTemplate>
        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!                      
    </LoggedInTemplate>
</asp:LoginView>

OR
Use following line of code to get current login user.

System.Web.Security.Membership.GetUser().ToString();

For SignOut use FormsAuthentication

    protected void LogOut_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();
        System.Web.Security.FormsAuthentication.SignOut();
        System.Web.Security.FormsAuthentication.RedirectToLoginPage();
//if you want to redirect to your desired page just use following line instead of RedirectToLoginPage
//Response.Redirect("myPage.aspx");
    }

Also see link below, may you get more help.

ASP.NET Login/Membership - How to logout?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM