title: asp.net Can I force every page to inherit from a base page? Also should some of this logic be in my master page?
body: <p>I have a web app that has a base page.</p>
  
  <p>Each page needs to inherit from this base page as it contains properties they all need as well as dealing with the login rights.</p>
  
  <p>My base page has some properties, eg: IsRole1, IsRole2, currentUserID, Role1Allowed, Role2Allowed.</p>
  
  <p>On the init of each page I set the properties "Role1Allowed" and "Role2Allowed"</p>
  
  <pre><code> Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  
      Role1Allowed = True
      Role2Allowed= False
  
  End Sub
  </code></pre>
  
  <p>The basepage then decides if the user needs redirecting.</p>
  
  <p>'Sample code so not exactly what is going to be, bug gives the idea</p>
  
  <pre><code> Protected Overridable Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If Role1Allowed And Not Role1 Then
  'Redirect somewhere
            End If 
         End Sub
  </code></pre>
  
  <p>The page then must override this pageload if they need anything else in it, but making sure they call the base pageload first.</p>
  
  <pre><code>  Protected Overrides Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      MyBase.Page_Load(sender, e)
      If Not IsPostBack Then
          BindGrid()
      End If
  End Sub
  </code></pre>
  
  <p>The other properties (IsRole1, IsRole, currentUserID) are also accessible by the page so it can be decided if certain things need doing based on the user.</p>
  
  <p>(I hope this makes sense)</p>
  
  <p>Ok so I have 2 questions</p>
  
  <ol>
  <li>Should this functionality be in the base page or should it somehow be in the master, and if so how would I get access to all the properties if it was?</li>
  <li>As there are multiple people working on this project and creating pages some are forgetting to inherit from this basepage, or call the base pageload when overriding it.
  Is there any way to force them to do this?</li>
  </ol>