【问题标题】:Application_PreRequestHandlerExecute redirect during 404 page not found找不到 404 页面期间的 Application_PreRequestHandlerExecute 重定向
【发布时间】:2016-02-05 15:52:03
【问题描述】:

我正在尝试记录来自我拥有的多个域的引荐来源网址,这些引荐来源网址会 301 永久重定向到我们的安全站点。所以我有两个通过 IIS 的网站。

http://www.cool_domain.com/ 将重定向到 https://www.real_domain.com/ 作为示例。在这个过程中,我想登录,然后在 PreRequestHandlerExecute 方法中进行重定向。

如果页面未找到 (404),则 Application_PreRequestHandlerExecute 不会触发。如果它确实存在,它会很好地触发。

void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
    if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
    {
        LogPage(Request);
        HttpContext.Current.Response.RedirectPermanent("https://www.real_domain.com/", true);
    }
}

我怎样才能让它在 404 期间触发?

【问题讨论】:

    标签: c# asp.net redirect global-asax


    【解决方案1】:

    愚蠢的错误,我应该知道...万一其他人遇到这种情况并且也有脑子,除非它是.net页面(aspx等),否则global.asax不会执行404错误。 )。

    【讨论】:

      猜你喜欢
      • 2013-03-31
      • 2020-10-03
      • 2017-03-04
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      相关资源
      最近更新 更多