ProviderException:InvalidCastException
我们的客户很少会经常遇到无效的强制转换异常,但情况有所不同 即 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 typeSystem.Int32
to typeSystem.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误消息告诉您,您正在尝试从整数类型转换(读取转换)为字符串类型,但转换不成功。这发生在 GetRolesForUser(String) 函数中。因此,也许您传递的是整数而不是字符串,并且解析不正确。无论哪种方式,我们都需要更多代码来确定。我希望这有帮助。
尝试确保每当您向需要字符串传递的对象提供整数时,首先调用 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: