为什么的Application_BeginRequest()两次火灾时清爽的浏览器? [英] Why does Application_BeginRequest() fire twice when refreshing browser?
问题描述
我观察,在我的Global.asax文件中的Application_BeginRequest事件还真有些混乱的行为(在ASP.NET MVC应用程序)。当通过调试器中运行,如果我刷新我的浏览器(IE7),此事件激发两次。如果我点击一个链接或以其他方式手动请求页面时,它触发一次 - 如预期
I'm observing some really confusing behavior with the Application_BeginRequest event in my Global.asax file (in an ASP.NET MVC app). When running through the debugger, if I Refresh my browser (IE7), this event fires twice. If I click a link or otherwise manually request a page, it fires once - as expected.
为什么刷新事业的BeginRequest开火两次?
Why does a refresh cause BeginRequest to fire twice?
我用下面addeded到的Global.asax.cs
I'm observing this with a brand new MVC project with the following addeded to Global.asax.cs
protected void Application_BeginRequest() {
//executed twice
}
有关的背景下,我想这个事件过程中一个新的对象添加到收藏HttpContext.Current.Items,所以它会在整个申请流程持续。很显然,我不希望这对单个刷新请求发生两次!
For context, I'm trying to add a new object to the HttpContext.Current.Items collection during this event, so it will persist through the entire request process. Obviously, I don't want this to happen twice for a single refreshed request!
推荐答案
你确定它真的2请求相同的URL?我认为第二个可能是一些动态JS,CSS或图像文件。尝试找出要么提琴手,或者在调试器
Are you sure it's really 2 request to the same URL? I would think that the second is probably some dynamic JS, CSS or image file. Try to find out either with Fiddler or by looking at HttpContext.Current.Request.Uri in the debugger
这篇关于为什么的Application_BeginRequest()两次火灾时清爽的浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!