Monday, November 9, 2009

Base Pages using C#.Net

Now i am come with the scenario clearing the session on each page writing the code.
for clearing the session in common place.
we can use some thing called base pages. so that we can keep the code in seprate place.
Step 1:
Create one class file with the name of basepages.cs.
This will contain the one method which will clear the session objects permanently.
Example:
public class BasePages:System.Web.UI.Page

{
public void clearSession()

{ if (Page.User.Identity.IsAuthenticated == false)
{ Session.Abandon();
Response.Redirect("login.aspx");
}
}
}
step 2
Create one login with the extension of .Aspx page.in the code behind just inherit that base class method.
public partial class SessionCheck : Performance.BasePages

{
protected void Page_Load(object sender, EventArgs e)
{
base.clearSession();
}
}