Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to do logout in asp.net in Asp.net programs of Asp.net/Ado.net/C#.net(Dotnet)
7296 Views
Introduction 
When you are making logout button you have to keep that button in master page so that it will appear in all the pages.While doing logout you have to remove the session variable because when you doing login you have used session variable to store the value of user name for some reason.In this example i done the same thing.In this example, i showed one label with the value of session variable and log out bitton. 
Master.aspx
<!-- Add this code in master page .aspx -->
<div class="loginDisplay">
            Welcome
                <asp:Label ID="lblUser" runat="server"></asp:Label>
            &nbsp;&nbsp;&nbsp;
                <asp:Button ID="Sign_out" runat="server" onclick="Sign_out_Click"
                    Text="Signout" />
</div>
Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace cdManage
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblUser.Text = Session["userName"].ToString();//taking value of variable during page load.showing in lable.
        }

        protected void Sign_out_Click(object sender, EventArgs e)
        {
            Session.Remove("userName");//remove the session variable
            Response.Redirect("Home.aspx");//redirect to login page or some other page.
        }
    }
}
Preview 
Best Lessons of "Asp.net/Ado.net/C#.net(Dotnet)"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details