【发布时间】:2015-03-31 21:00:53
【问题描述】:
我有一个 ASP.NET MVC 应用程序,我正在使用 ASP.NET Identity 2。我遇到了一个奇怪的问题。 ApplicationUser.GenerateUserIdentityAsync 被浏览器向我的网站发出的每个请求调用。我添加了一些Trace.WriteLine,这是删除 IIS 输出后的结果:
IdentityConfig.Configuration called
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Content/bootstrap.css
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Scripts/modernizr-2.8.3.js
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Content/site.css
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Scripts/jquery-2.1.3.js
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Scripts/bootstrap.js
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Scripts/respond.js
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Scripts/script.js
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Glimpse.axd?n=glimpse_client&hash=8913cd7e
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Glimpse.axd?n=glimpse_metadata&hash=8913cd7e&callback=glimpse.data.initMetadata
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Glimpse.axd?n=glimpse_request&requestId=6171c2b0-b6e5-4495-b495-4fdaddbe6e8f&hash=8913cd7e&callback=glimpse.data.initData
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/Glimpse.axd?n=glimpse_sprite&hash=8913cd7e
ApplicationUser.GenerateUserIdentityAsync called url: http://localhost:54294/__browserLink/requestData/38254292a54f4595ad26158540adbb6a?version=2
如果我运行由模板创建的默认 MVC 应用程序,我会得到:
IdentityConfig.Configuration called
只有当我登录时,它才会调用ApplicationUser.GenerateUserIdentityAsync。
我找遍了所有我认为可能存在的地方,但没有找到任何结果。我正在使用(如果有帮助)
StructureMap 3
Elmah
Glimpse
ASP.NET MVC 5
EF6
ASP.NET Identity 2
其他信息
我将用户直接添加到数据库中,而不使用 UserManage。我不确定它是否对身份有任何问题。
更新
我已经删除了数据库,但它不再发生了。发生了什么?
更新 2
它发生在我的谷歌浏览器中(我使用 glimpse 监控 SQL 连接),在删除存储的 cookie 后,它没有发生。用其他浏览器登录会不会出现这个问题?
更新 3
同时注销 - 登录似乎可以暂时解决问题。
【问题讨论】:
-
这可能无济于事,只是一个想法。您是否尝试在发布模式而不是调试模式下运行?调试模式可能会进行大量额外调用
-
@ScottSelby 好笑!我已经在发布模式下运行它,一切都很好。然后我将它发布到我的服务器上,它又发生了:|
-
ASP.NET Identity 是否使用会话?这听起来像是在请求之间没有保留会话 ID 的情况。如果是这样,请尝试设置一个虚拟会话变量。
-
@SimonSvensson 看来 ASP.NET Identity 不使用会话。
标签: c# asp.net asp.net-mvc iis asp.net-identity