我正在使用自己的自定义身份验证与IIS,我希望每个页面上的服务器加载(无论什么类型的文件)首先检查应用程序变量,以查看用户是否经过身份验证并有权查看该站点.在global.asax中,这可能是:
void Application_Start(Object Sender, EventArgs e)
{
if(Application["username"] == null)
{
Response.redirect("login.aspx");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是这个站点有多个子根.也就是说,http://example.com/site1 是一个与http://example.com/site2完全不同的网站.因此,我想说Application_Start函数在site1上工作但不影响site2.
如果global.asax可以在目录级别自定义,那么这不会是一个问题.但由于每个服务器只有一个global.asax,因此我无法实现此解决方案.
global.asax还有哪些替代方案?或者global.asax能以某种方式为每个目录不同吗?