Hi dgunners,
Here i have created sample. You need to use the same logic in your project.
HTML
Master.master
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:LinkButton ID="lbSignUp" PostBackUrl="~/Registration.aspx" runat="server" Text="Sign Up" />
</td>
<td>
<asp:LinkButton ID="lbLogin" PostBackUrl="~/Login.aspx" runat="server" Text="Login" />
</td>
<td>
<asp:LinkButton ID="lbHome" PostBackUrl="~/Home.aspx" runat="server" Text="Home" />
</td>
<td>
<asp:LinkButton ID="lbContactUs" PostBackUrl="~/ContactUs.aspx" runat="server" Text="ContactUs" />
</td>
<td>
<asp:LinkButton ID="lbLogout" PostBackUrl="~/Login.aspx" runat="server" Text="Logout"
Visible="false" OnClick="Click" />
</td>
</tr>
</table>
<br />
<br />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
Registration.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server" Width="150px" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="150px" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" Width="150px" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnSugnUp" runat="server" Text="Submit" />
</td>
</tr>
</table>
</asp:Content>
Login.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Login ID="Login1" runat="server" OnAuthenticate="OnAuthenticate">
</asp:Login>
</asp:Content>
Home.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
Well Come to Excelasoft Solution Pvt. Ltd.
</asp:Content>
ContactUs.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
This is Contact Us page.
</asp:Content>
Error.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
You do not have access the page.
<br />
If you are not a registered user use the below link for registration.
<br />
<asp:HyperLink ID="HyperLink1" NavigateUrl="~/Registration.aspx" runat="server" Text="Sign Up" />
<br />
If you are already a user please login to access the page.
<br />
<asp:HyperLink ID="HyperLink2" NavigateUrl="~/Login.aspx" runat="server" Text="Login" />
</asp:Content>
Code
Master.master.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ValidUser"] != null && Session["ValidUser"] == "UserLoggedIn")
{
lbLogout.Visible = true;
}
}
protected void Click(object sender, EventArgs e)
{
Session["ValidUser"] = null;
}
Login.aspx.cs
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string password = Login1.Password;
if (userName.ToLower() == "test" && password.ToLower() == "test")
{
Session["ValidUser"] = "UserLoggedIn";
Server.Transfer("~/Home.aspx");
}
}
Home.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ValidUser"] == null && Session["ValidUser"] != "UserLoggedIn")
{
Server.Transfer("Error.aspx");
}
}
ContactUs.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ValidUser"] == null && Session["ValidUser"] != "UserLoggedIn")
{
Server.Transfer("Error.aspx");
}
}
Screenshot