Asp.net 成员资格错误

发布于 2024-07-12 09:03:54 字数 993 浏览 10 评论 0原文

我们有一个正在运行的业务系统,但时不时会发生错误。 该错误是根据来自 asp.net 会员资格提供程序的堆栈跟踪得出的。 当前登录的用户似乎并不重要。 据我所知,数据库中的 asp.net 成员资格表很好。

生成错误的代码行示例:

if (Membership.GetUser() != null)

错误描述:

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() +141
System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +96
System.Web.Security.SqlMembershipProvider.GetNullableString(SqlDataReader reader, Int32 col) +35
System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1110
System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +82
System.Web.Security.Membership.GetUser() +19

有人知道出了什么问题吗?


更新:我们找不到此错误的解决方案。 但最终它消失了。

现在,当我们迁移到另一台服务器时,此错误完全瘫痪了我们的应用程序。 我完全没有主意了:(

We have a live running business system with an error which occurs from time to time. The error is according to the stack trace comming from the asp.net membership provider. It does not seem to matter which user is currently logged on. As far as i can tell the asp.net membership tables in the database are fine.

Example of a code row generating the error:

if (Membership.GetUser() != null)

Error description:

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

Stack Trace:

[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.]
System.Data.SqlClient.SqlBuffer.get_String() +141
System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +96
System.Web.Security.SqlMembershipProvider.GetNullableString(SqlDataReader reader, Int32 col) +35
System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1110
System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +82
System.Web.Security.Membership.GetUser() +19

Does anyone have an idea of what's wrong?


Update: We could not find a solution for this error. But eventually it disapeared.

Now when we migrated to another server this error totally cripples our application. I'm totally out of ideas :(

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

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

发布评论

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

评论(1

非要怀念 2024-07-19 09:03:54

在 Membership.GetUser() 调用周围放置一个 try/catch 块并记录用户名。 您可以通过调用Membership.GetCurrentUserName() 获取用户名。

一旦您有了一个会导致问题的用户名,请查看 SQL 中的成员资格表并检查“注释”字段。 我的猜测是,“注释”字段中发生了一些有趣的事情 - 也许有一些奇怪的 unicode 字符遇到问题,或者该字段中的数据太多,等等。

另外,尝试在会员数据库上调用 dbo.aspnet_Membership_GetUserByName遇到问题的用户,看看会得到什么结果。

Put a try/catch block around the Membership.GetUser() call and log the username. You can get the username by calling Membership.GetCurrentUserName().

Once you have a username this is causing problems for, look at the membership table in SQL and check out the Comments field. My guess is that something funny is going on in the Comments field - maybe there are some weird unicode characters it's having trouble with, or maybe there's too much data in that field, etc.

Also, try calling dbo.aspnet_Membership_GetUserByName on the membership database for the user that it had trouble with and see what result you get.

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