调用 SqlMembershipProvider GetUser 时出现无效转换异常

发布于 2024-11-01 05:15:57 字数 1149 浏览 3 评论 0原文

我正在使用 ASP.NET SqlMembershipProvider 在 Web 应用程序上实现授权,但在调用 GetUser 方法时它会随机抛出无效的强制转换异常。

我可以登录并导航页面,一切都很好,但是在随机点上,繁荣,它崩溃了,并抛出异常:

Unable to cast object of type 'System.Int32' to type 'System.String'

查看堆栈跟踪,您可以清楚地看到它是由会员提供者引起的:

[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.]
   System.Data.SqlClient.SqlBuffer.get_String() +5002910
   System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +55
   System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1169
   System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +63
   System.Web.Security.Membership.GetUser() +19
   _Default.LoadLeadOverview() in \\file1\default.aspx.vb:169
   _Default.Page_Load(Object sender, EventArgs e) in \\file1\default.aspx.vb:30
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

我有过环顾四周,发现其他人也有同样的问题,但没有解决方案。任何想法都会受到欢迎。

I am implementing authorisation on a web application using the ASP.NET SqlMembershipProvider, but it is randomly throwing an invalid cast exception when calling the GetUser method.

I can log in, and navigate the pages all fine, but than at random points, boom, it craps out, and throws the exception:

Unable to cast object of type 'System.Int32' to type 'System.String'

Looking at the stack trace you can clearly see it is being caused by the Membership Provider:

[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.]
   System.Data.SqlClient.SqlBuffer.get_String() +5002910
   System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +55
   System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1169
   System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +63
   System.Web.Security.Membership.GetUser() +19
   _Default.LoadLeadOverview() in \\file1\default.aspx.vb:169
   _Default.Page_Load(Object sender, EventArgs e) in \\file1\default.aspx.vb:30
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

I have had a look around and found other people with the same issue, but no solution. Any thoughts would be welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GRAY°灰色天空 2024-11-08 05:15:57

虽然我没有采取任何措施来具体解决这个问题,但我已经几周没有看到它了。回想起来,我同时在多个浏览器中使用相同的帐户测试该网站,多次登录和退出,似乎就在那时问题出现了。现在所有的CSS和其他跨浏览器的东西都已经解决了,我没有那么频繁地使用多浏览器,而且不是同时使用,看起来还不错。

Whilst I haven't done anything to specifically resolve this issue, I haven't seen it in a couple of weeks. Looking back, I was testing the site in multiple browsers at the same time, with the same account, logging in and out a lot, and that seemed to be when then problem came up. Now all the CSS and other cross-browser stuff has been settled, I'm not using multi browsers so heavily, and not at the same time and it seems to be fine.

二手情话 2024-11-08 05:15:57

您的某些用户是否可能将所有数字作为用户名?可能是自动类型在某个地方装箱错误。

Is it possible some of your users have all digits as their username? It might be that auto type is boxing wrong somewhere along the way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文