473,840 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET Page Inheritance flow?

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 CheckPermission s() as listed
below at the beginning of the page_load....

I guess what I wanted to avoid was having to explicitly put the
this.CheckPermi ssions 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.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
string pageName = Page.ToString() ;
pageName = pageName.Replac e("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 CheckPermission s()
{
string pageName = Page.ToString() ;
pageName = pageName.Replac e("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(objec t sender, System.EventArg s e)
{
this.CheckPermi ssions(); //check if user can view page.
...
'--proceed to load page...

'--while debugging, WebFormBase.Pag e_Load() is called now? How to make
this run at the beginning of this event so I don't have to call
CheckPermission s explicitly?
}
}
Nov 19 '05 #1
3 1288
> 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.


Sorry this doesn't answer your question directly, but you don't need to do
this. ASP.NET provides automatic authorization checks for you based upon
the identity of the user or any roles that s/he is in. Check out:

http://msdn.microsoft.com/library/de...entication.asp

Even if this doesn't satisify your needs, you don't need to necessarily put
this check in a base class. You can put the check in global.asax in the Application_Aut horizeRequest
event. You can then do whatever checks are necessary and call Response.Redire ct()
and/or Application.End Request() to fail the call such that the page the user
is trying to access won't be seen.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #2
Thanks Brock! I forgot about the AuthorizeReques t event. Just to satisfy my
curiosity, if you have any links related my original post that would be
helpful too!
Dave

"Brock Allen" wrote:
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.


Sorry this doesn't answer your question directly, but you don't need to do
this. ASP.NET provides automatic authorization checks for you based upon
the identity of the user or any roles that s/he is in. Check out:

http://msdn.microsoft.com/library/de...entication.asp

Even if this doesn't satisify your needs, you don't need to necessarily put
this check in a base class. You can put the check in global.asax in the Application_Aut horizeRequest
event. You can then do whatever checks are necessary and call Response.Redire ct()
and/or Application.End Request() to fail the call such that the page the user
is trying to access won't be seen.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #3
> Thanks Brock! I forgot about the AuthorizeReques t event. Just to
satisfy my curiosity, if you have any links related my original post
that would be helpful too! Dave


Umm, not off the top of my head. One way to insure the order is to instead
override OnLoad() instead of handling the Page_Load event. So then in your
OnLoad() you do whatever you need first, then call base.OnLoad() if your
authorization checks succeed.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3755
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
0
2435
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as <fo:layout-master-set> <fo:simple-page-master margin-left="0.5in" margin-right="0.5in" page-width="8.5in" margin-bottom="0.5in" master-name="Section-odd-page" margin-top="0.5in" page-height="14in"> <fo:region-after region-name="xsl-region-after-odd"
1
352
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
60
4959
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
0
9863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9702
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10607
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7845
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.