Asp.net 从Global.asax文件重定向

Asp.net 从Global.asax文件重定向,asp.net,Asp.net,我们有一家商店,我们与一家公司签订合同要对其进行改造。他们将以下内容添加到我们的Global.asax文件中: protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { string exFilePath = Request.AppRelativeCurrentExecutionFilePath.ToLower(); if ((!exFilePath.EndsWith(".aspx

我们有一家商店,我们与一家公司签订合同要对其进行改造。他们将以下内容添加到我们的Global.asax文件中:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
    string exFilePath = Request.AppRelativeCurrentExecutionFilePath.ToLower();

if ((!exFilePath.EndsWith(".aspx") && !exFilePath.EndsWith(".ashx"))
     || exFilePath.StartsWith("~/admin")
     || exFilePath.StartsWith("~/js")
     || exFilePath.StartsWith("~/app_themes")
     || exFilePath.StartsWith("~/assets")
     || exFilePath.StartsWith("~/errors")
     || exFilePath.StartsWith("~/fckeditor")
     || exFilePath.StartsWith("~/images")
     || exFilePath.StartsWith("~/layouts")
     || exFilePath.StartsWith("~/webcharts")
     )
{
    return;
}
    else
    {
        AccessHelper.HandleAnonymousUsers();
    }
}
其目的是让任何人进入我们的一个页面,进入登录屏幕,除非他们进入这些不需要登录保护的文件夹

我现在需要让他们转到http://[mysite]/vendorstore/PasswordHelp.aspx?Key=123&Check=V7Xc1BsH913V

如果有人能帮我修改全局文件,我将不胜感激。我试图添加
||exFilePath.EndsWith(“~/Passwordhelp.aspx”)
但那没用


谢谢

将EndsWith替换为StartsWith

将以下内容添加到条件中:

|| exFilePath.StartsWith("~/vendorstore/passwordhelp")

将您的if更改为更像:

if(exeFilePath.EndsWith("/passwordhelp.aspx") || 
  (!exFilePath.EndsWith(".aspx") && !exFilePath.EndsWith(".ashx"))
 || exFilePath.StartsWith("~/admin")
 || exFilePath.StartsWith("~/js")
 || exFilePath.StartsWith("~/app_themes")
 || exFilePath.StartsWith("~/assets")
 || exFilePath.StartsWith("~/errors")
 || exFilePath.StartsWith("~/fckeditor")
 || exFilePath.StartsWith("~/images")
 || exFilePath.StartsWith("~/layouts")
 || exFilePath.StartsWith("~/webcharts")
 )

确保您使用的是小写(“passwordhelp.aspx”),并确保它在您的密码之前!exeFilePath.EndsWith(“.aspx”)和“.ashx”检查。

完美!也谢谢你的解释,它给了我一些关于全局文件的额外有用的知识。