Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Type Of Super Class??

Status
Not open for further replies.

Smeat

Programmer
Mar 27, 2004
193
GB
Hi All

Each of my .ASPX pages inherits from 1 of 2 available base pages, each of which makes up part of a chain.

For example, I have 2 web pages:

Page1.aspx which inherits from CustomBasePage1
and
Page2.aspx which inherits from CustomBasePage1 which inherits from CustomBasePage2

In my CustomBasePage1, I have a method which takes a different action depending on which class the .aspx page inherited from.

How can I determine if the .aspx page inheritted from CustomBasePage1 OR CustomBasePage2

TIA

Smeat
 
Correction

Page2.aspx which inherits from CustomBasePage1 which inherits from CustomBasePage2

should read

Page2.aspx which inherits from CustomBasePage2 which inherits from CustomBasePage1

Thanks

Smeat
 
In case it helps anyone else, here is how I solved my problem:

Code:
    #region Validate User Access Rights

    /// <summary>
    /// Ensure the user is not trying to byepass licensing
    /// </summary>
    protected virtual void ValidateUserAccess()
    {
        LoyaltyLogistix.Automotive.Autolog.Library.Security.AutologIdentity identity = GetIdentity();
        bool isLMSUser = (identity.LicenseMode == LoyaltyLogistix.Automotive.Autolog.Library.Security.AutologIdentity.LicensingMode.LMS);
        identity = null;

        if (isLMSUser == true)
        {
            //If this is not an instance of CustomerPageBaseLMS then
            //the user has requested a page form the Autolog product and the
            //request must be denied.
            Type currentType = this.GetType();
            bool isLMSType = false;
            do
            {
                if (currentType.BaseType == typeof(CustomPageBaseLMS))
                {
                    isLMSType = true;
                    break;
                }
                else
                {
                    currentType = currentType.BaseType;
                }
            } while (currentType != typeof(object));

            if(! isLMSType)
            {
                throw new UnauthorizedAccessException("You are not authorised to view this page, please check you license agreement.");
            }
        }
    }

    #endregion

Ta

Smeat
 
You could also have used the "is" keyword as in:

Code:
if (currentType is CustomPageBaseLMS)
{
    //...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top