Invalid Cast Exception throws SqlMembershipProvider GetUser

I am authorizing in a web application using ASP.NET SqlMembershipProvider, but when I call the GetUser method, it accidentally throws an invalid casting exception.

I can log in and navigate the pages all is well, but not at random points, a boom, it twitches and throws an exception:

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

By looking at the stack trace, you can clearly see that this is 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 looked around and found other people with the same problem, but without a solution. Any thoughts would be welcome.

+4
source share
2 answers

While I did nothing to specifically solve this problem, I did not see it in a couple of weeks. Looking back, I tested the site in several browsers at the same time, with the same account, login and logout, and it seemed when the problem arose. Now all CSS and other cross-browser materials have been resolved, I don’t use many browsers so much, and not at the same time, and it seems that everything is in order.

+1
source

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

0
source

Source: https://habr.com/ru/post/1347918/


All Articles