Application_BeginRequest事件未触发

本文关键字:事件 BeginRequest Application | 更新日期: 2023-09-27 17:55:55

我正在使用Application_BeginRequest事件,该事件应该在向某个网址发出请求时触发。

protected void Application_BeginRequest(Object sender, EventArgs e)
    {            
        if (HttpContext.Current.Request.Url.ToString() == DummyPageUrl)
        {
            RegisterCacheEntry();
        }
    }

这是我用来请求 url 的代码:

private void HitPage()
    {
        WebClient client = new WebClient();
        client.DownloadData(DummyPageUrl);            
    }

但Application_BeginRequest事件并没有被解雇。我也在web.config中尝试过这个:

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>

这行不通。请帮助我。

Application_BeginRequest事件未触发

你在global.asax工作吗?

在 Global.asax 页面中试试这个....

 void Application_BeginRequest(object sender, EventArgs e)
    {

    }