title: what alternatives are there to using global.asax?
body: <p>I am using my own custom authentication with IIS, and I want the server on <i>every</i> page load (no matter what type of file) to first check the Application variable to see if the user is authenticated and authorized to see the site. In global.asax this could be:</p>
  
  <pre><code>void Application_Start(Object Sender, EventArgs e)
  {
    if(Application["username"] == null)
    {
      Response.redirect("login.aspx");
    }
  }
  </code></pre>
  
  <p>The problem is that this site has multiple sub-roots. That is, <a href="http://example.com/site1" rel="noreferrer">http://example.com/site1</a>  is a completely different website from <a href="http://example.com/site2" rel="noreferrer">http://example.com/site2</a> .  Therefore, I would like said Application_Start function to work on site1 but not affect site2.</p>
  
  <p>If global.asax was customizable at directory level, then this wouldn't be a problem. But since there is only one global.asax per <i>server</i> I cannot implement this solution.</p>
  
  <p>What alternatives are there to global.asax? or can global.asax be different somehow for each directory?</p>