Profile_OnMigrateAnonymous 事件多次触发
我们有一个 HTTPModule,其唯一目的是进行“url 重写”。根据 HTTPModule 的定义,所有浏览器请求(html、css、javascript、图像等)都会经过此类的事件处理程序。
在登录过程中,我们在 Global.asax 的 Profile_OnMigrateAnonymous 事件处理程序中捕获用户从“匿名”用户切换到“登录”用户的时刻。我们发现的一个问题是,当用户登录时,Profile_OnMigrateAnonymous 事件似乎会针对请求中的每个资源(即 html、css、javascript、图像等)触发,以便为用户生成页面。据我了解,该事件只会触发一次。为什么会多次发射?是我们注册了“url重写”HTTPModule的结果吗?有没有一种方法可以将应用程序配置为仅触发该事件一次?
We have an HTTPModule whose sole purpose is to do "url rewriting". By definition of an HTTPModule, ALL browser requests (html, css, javascript, images, etc) go through the event handlers of this class.
During the signin process, we are catching the moment when the user switches from "anonymous" to "signed-in" user in the Global.asax's Profile_OnMigrateAnonymous event handler. One issue we're finding is that when the user signs in, the Profile_OnMigrateAnonymous event fires, seemingly, for possibly EVERY resource within the request to generate the page to the user - namely, the html, css, javascript, images, etc. It was my understanding that this event will fire only ONCE. Why would it be firing multiple times? Is it a result of our registered "url rewriting" HTTPModule? Is there a way we can configure the application to only fire that event once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于普通资源请求(css/js/img 等),IIS 直接处理请求。它仅向 asp_net 工作程序传递对特定文件名(例如 .aspx 和 .asmx)的请求。
您的 HTTPModule 基本上是强制 IIS 将所有请求转发到工作进程,因此每个请求都会触发 Profile_OnMigrateAnonymous。
我认为您无法绕过对 Profile_OnMigrateAnonymous 的调用,但是您可以实现一些代码来检查 .aspx/.ascx 等文件名,然后才执行指定的实际操作。
For normal resource reqeusts (css/js/img etc) IIS handles the request directly. It only passes to the asp_net worker requests for specfic filenames (such as .aspx and .asmx).
Your HTTPModule is basically forcing IIS to forward all requests to the worker process, hence each request is firing off the Profile_OnMigrateAnonymous.
I don't think you can bypass the call to Profile_OnMigrateAnonymous, however you could implement a bit of code to check for a an .aspx/.ascx etc file name and only then perform the actual actions specified.