Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:15:05+00:00 2026-05-23T13:15:05+00:00

I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class

  • 0

I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class I have a bool property that checks to see if a page is secure or not. Initially, I put the code in the PreInit event (of the base class), but after thinking about it, my derived pages will not be able to set the bool value before PreInit. I then thought of setting the value in PreInit of the dervcied pages and checking that value in PageInit of the base class, but what if I need to use the PreInit in the derived page?

I thought about using partial methods, but I don’t think I can do that because the page events are not partials in System.Web.Ui.Page, right?

My BasePage class is an abstract class, by the way.

This is what I have now (I have not tested this, but assumed it may work):

public abstract partial class BasePage: System.Web.UI.Page
{
   public bool IsSecure { get; set; }

   protected void Page_Init(object sender, EventArgs e)
        {
            if (!IsSecure) return;
            if (PageMaster == null)
                return;
            if (!PageMaster.IsUserLoggedIn)
            {
                HttpContext.Current.Response.Redirect("~/WebForms/LogIn.aspx");
            }
        }  
}


public partial class _Default : BasePage
{
   protected void Page_PreInit(object sender, EventArgs e)
   {
     IsSecure = true;
   }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:15:06+00:00Added an answer on May 23, 2026 at 1:15 pm

    A better solution may be to override the OnInit method in your base class. You can now still handle the init event in your pages, with the secure check carried out before the event is raised.

    so:

    public abstract partial class BasePage: System.Web.UI.Page
    {
        public bool IsSecure { get; set; }
    
        protected override void OnInit(EventArgs e)
        {
            if (!IsSecure) return;
            if (PageMaster == null)
                return;
            if (!PageMaster.IsUserLoggedIn)
            {
                HttpContext.Current.Response.Redirect("~/WebForms/LogIn.aspx");
            }
    
            base.OnInit(e)
        }  
    }
    
    public partial class _Default : BasePage
    {   
       protected void Page_PreInit(object sender, EventArgs e)
       {
          IsSecure = true;
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web form page Default.aspx, which inherits from a BasePage class that
I have created a class called BasePage which inherits System.Web.UI.Page. On this page I've
I have created a PHP-script to update a web server that is live inside
I have created a few small flash widgets that stream .mp3 audio from an
I'm building a asp.net web site i build a class localiziedpage that inherit from
How do I create a new event in a base page class that fires
My problem is this I have a base page that creates content dynamically. There
I have usercontrols which inherit a base class which looks like this: BasePage.cs: using
Have created an attribute property in TableView1.h and pushing that attributes value to another
I have a BasePage.java (together with a BasePage.html ). My base page is basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.