In the following code I am overriding the MasterPage class's onLoad event. What I am doing is, I check whether session variables have been set i.e. if the user has actually logged in into the system. I have created the baseclass titled baseClass.
Now in the masterpage I wrote the following code, in this way I am sparing the onLoad eventhandler of my masterpage from checking session related information
For further reading you can click here
public class baseClass : System.Web.UI.MasterPage
{
public baseClass()
{
//
// TODO: Add constructor logic here
//
}
protected override void OnLoad(EventArgs e)
{
try
{
if (Session["usrPrivilege"].ToString().Equals("ADMIN"))
{
base.OnLoad(e);
}
else
Response.Redirect("~/Default.aspx");
}
catch (NullReferenceException ex)
{
Response.Redirect("~/Default.aspx");
}
catch
{
base.OnLoad(e);
}
}
}
public partial class Pages_ADMIN_MasterPage :baseClass
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (IsPostBack == false)
{
//My code goes here
}
}
catch (System.Exception ex)
{
//My code for exception handling
}
}
}
No comments:
Post a Comment