开发者

Application_EndRequest(object sender, EventArgs e) being called multiple times in asp.net

In my application i'm defining a class which implements ihttpmodule and it contains following methods

  public void Init(HttpApplication application)
    {
        application.EndRequest += new EventHandler(Application_EndRequest);
    }


 private void Application_EndRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;


        IObjectContainer objectClient = context.Items[KEY_DB4O_CLIENT] as IObjectContainer;

        if (objectClient != null)
        {
            objectClient.Close();
        }

        objectClient = null;
        context.Items[KEY_DB4O_CLIENT] = null;
    }

when开发者_StackOverflow i try to run the application and debug it, i notice one strange thing:

in chrome private void Application_EndRequest(object sender, EventArgs e) is getting executed 3 times when the application starts and again 3 times when the application ends.

in Internet explorer private void Application_EndRequest(object sender, EventArgs e) is getting executed 2 times when the application starts and again 2 times when the application ends.

Why is Application_EndRequest getting executed multiple times. Is it not supposed to run only once ?

And also i would like to know the difference between Visual Studio Development Web Server and IIS ?

What is the difference between both of me.

Please help me

Thanks in anticipation


Application_EndRequest() will be called as many times as there are requests handled by the runtime. With the VSDev Server, that will be -every- request; including ones for images, and other various resources the browser might look for... such as a bookmark icon image.

That could also explain the difference between the browsers; IE and Chrome may have differences in what extra things they are trying to request, particularly re: the site icon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜