ProviderException:InvalidCastException

发布于 2024-08-07 11:29:01 字数 1235 浏览 4 评论 0原文

我们的客户很少会经常遇到无效的强制转换异常,但情况有所不同 即 InvalidCastException / ProviderException,但两者都生成自 方法调用: System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)

另一个变体是:

异常类型:InvalidCastException
异常消息:无法将 System.Int32 类型的对象转换为 System.String 类型。

我查看了应用程序事件日志,其中显示:

Stack trace:
   at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
   at System.Web.Security.RolePrincipal.IsInRole(String role)
   at System.Web.Configuration.AuthorizationRule.IsTheUserInAnyRole(StringCollection roles, IPrincipal principal)
   at System.Web.Configuration.AuthorizationRule.IsUserAllowed(IPrincipal user, String verb)
   at System.Web.Configuration.AuthorizationRuleCollection.IsUserAllowed(IPrincipal user, String verb)
   at System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)*

有人遇到过这个问题吗?如果有,解决方法是什么?

谢谢

JS

Few of our clients are regularly getting invalid cast exception, with variations
i.e. InvalidCastException / ProviderException, but both generating from
method call: System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)

The other variation is:

Exception type: InvalidCastException
Exception message: Unable to cast object of type System.Int32 to type System.String.

I had a look at application event log which shows:

Stack trace:
   at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
   at System.Web.Security.RolePrincipal.IsInRole(String role)
   at System.Web.Configuration.AuthorizationRule.IsTheUserInAnyRole(StringCollection roles, IPrincipal principal)
   at System.Web.Configuration.AuthorizationRule.IsUserAllowed(IPrincipal user, String verb)
   at System.Web.Configuration.AuthorizationRuleCollection.IsUserAllowed(IPrincipal user, String verb)
   at System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)*

Has anyone come across this issue, and if so what is the fix?

Thanks

JS

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

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

发布评论

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

评论(1

半岛未凉 2024-08-14 11:29:01

该错误消息告诉您,您正在尝试从整数类型转换(读取转换)为字符串类型,但转换不成功。这发生在 GetRolesForUser(String) 函数中。因此,也许您传递的是整数而不是字符串,并且解析不正确。无论哪种方式,我们都需要更多代码来确定。我希望这有帮助。

尝试确保每当您向需要字符串传递的对象提供整数时,首先调用 toString() 函数。例如:

GetRolesForUser(someInt32Var.toString())

The error message is telling you that you are attempting to cast (read convert) from an integer type to a string type and that that cast was not successful. This occurred in the GetRolesForUser(String) function. So perhaps you are passing an integer in instead of a string and it is being parsed incorrectly. Either way we'll need more code to be sure. I hope this helps.

Try making sure that whenever you give an integer to something that requires a string pass call the toString() function on it first. For example:

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