G
Guest
Hi,
I want to create a base Webform where I want to put code to check if the
logged on user is allowed to view the page.
I want to put this code in once place and have all secured webforms inherit
from this base class
What I would like to happen is that the code in the base class be called
first (maybe in the Page_Load, but I'm not sure) to do the checking. My code
is below. The default flow for asp.net seems that any base class events are
called *after* descendent event runs. One way I got my base class code to
fire was by calling a custom funtion called CheckPermissions() as listed
below at the beginning of the page_load....
I guess what I wanted to avoid was having to explicitly put the
this.CheckPermissions in every descendant page. It would seem to me that if
a class is inherits another class the base class code would be called first
but I haven't done this type of thing yet so I'm not sure.
Base page
------------
public class WebFormBase : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string pageName = Page.ToString();
pageName = pageName.Replace("ASP.", "").Replace ("_", ".");
//--Code to check if the current logged on user has rights to view the
value of pageName from the permissions table.
}
protected void CheckPermissions()
{
string pageName = Page.ToString();
pageName = pageName.Replace("ASP.", "").Replace("_", ".");
//--Code to check if the current logged on user has rights to view the
value of pageName from the permissions table.
}
}
Descendent Page inherits WebFormBase..
----------------------------------------------
public class Home : WebFormBase
{
protected void Page_Load(object sender, System.EventArgs e)
{
this.CheckPermissions(); //check if user can view page.
...
'--proceed to load page...
'--while debugging, WebFormBase.Page_Load() is called now? How to make
this run at the beginning of this event so I don't have to call
CheckPermissions explicitly?
}
}
I want to create a base Webform where I want to put code to check if the
logged on user is allowed to view the page.
I want to put this code in once place and have all secured webforms inherit
from this base class
What I would like to happen is that the code in the base class be called
first (maybe in the Page_Load, but I'm not sure) to do the checking. My code
is below. The default flow for asp.net seems that any base class events are
called *after* descendent event runs. One way I got my base class code to
fire was by calling a custom funtion called CheckPermissions() as listed
below at the beginning of the page_load....
I guess what I wanted to avoid was having to explicitly put the
this.CheckPermissions in every descendant page. It would seem to me that if
a class is inherits another class the base class code would be called first
but I haven't done this type of thing yet so I'm not sure.
Base page
------------
public class WebFormBase : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string pageName = Page.ToString();
pageName = pageName.Replace("ASP.", "").Replace ("_", ".");
//--Code to check if the current logged on user has rights to view the
value of pageName from the permissions table.
}
protected void CheckPermissions()
{
string pageName = Page.ToString();
pageName = pageName.Replace("ASP.", "").Replace("_", ".");
//--Code to check if the current logged on user has rights to view the
value of pageName from the permissions table.
}
}
Descendent Page inherits WebFormBase..
----------------------------------------------
public class Home : WebFormBase
{
protected void Page_Load(object sender, System.EventArgs e)
{
this.CheckPermissions(); //check if user can view page.
...
'--proceed to load page...
'--while debugging, WebFormBase.Page_Load() is called now? How to make
this run at the beginning of this event so I don't have to call
CheckPermissions explicitly?
}
}