HttpContext.Current.User.IsInRole 引发 HttpUnhandledException。为什么?
当我在本地主机上工作时,它工作得完美无缺。
但是,当我将应用程序部署到另一台服务器时,它开始引发异常。
基本上,这是导致异常的指令:
HttpContext.Current.User.IsInRole(*roleName*)
其中 roleName 是表示应用程序中不同角色的字符串。
引发异常:
System.Web.HttpUnhandledException
更新:这是对用户进行身份验证的方式。
protected void LoginControl_Authenticate(object sender, AuthenticateEventArgs e)
{
Page.Validate();
if (!Page.IsValid) return;
if (MyAuthenticate(LoginControl.UserName, LoginControl.Password))
{
if (LoginControl.RememberMeSet == true)
{
createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), true);
}
else
{
createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), false);
}
e.Authenticated = true;
Response.Redirect(FormsAuthentication.GetRedirectUrl(LoginControl.UserName, true));
}
else
{
e.Authenticated = false;
}
如果它与用户身份验证有关,我缺少什么?提前致谢。
更新:谢谢大家。我刚刚完成远程调试并意识到这是实际错误:
现在,情况是这样:用户在登录页面进行了身份验证。所以,我认为这不是与数据库连接的问题。否则,用户将无法将登录页面传递到 MasterPage(引发此错误的地方)。
我可以缺少什么吗?再次感谢,
While I was working on my localhost it worked flawlessly.
However, when I deployed the application to another server it started to raise an exception.
Basically, this is the instruction that causes the Exception:
HttpContext.Current.User.IsInRole(*roleName*)
where roleName is a string representing the different roles in the application.
Exception fired:
System.Web.HttpUnhandledException
Update: This is how the user is being authenticated.
protected void LoginControl_Authenticate(object sender, AuthenticateEventArgs e)
{
Page.Validate();
if (!Page.IsValid) return;
if (MyAuthenticate(LoginControl.UserName, LoginControl.Password))
{
if (LoginControl.RememberMeSet == true)
{
createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), true);
}
else
{
createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), false);
}
e.Authenticated = true;
Response.Redirect(FormsAuthentication.GetRedirectUrl(LoginControl.UserName, true));
}
else
{
e.Authenticated = false;
}
If it is related to the user authentication, what am I missing? Thanks in advance.
UPDATE: Thanks to all. I have just done a Remote Debugging and realize this is the actual error:
Now, this is the situation: the User was authenticated in the login page. So, I think it is not a problem with the connection to the DB. Otherwise, the User wouldn't have been able to pass the login page to the MasterPage (where this error is being raised).
What can I be missing? Thanks again,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在黑暗中狂野刺伤,但内部异常可能是空引用异常,这是由于用户未在服务器上进行身份验证而导致的,因此 HttpContext.Current.User 为空。我敢打赌,这只是在实时 Web 服务器上未启用 Windows 集成身份验证或类似的身份验证设置问题。
Wild stab in the dark but the inner exception is probably a null reference exception being caused by the fact the user is not authenticated on the server so HttpContext.Current.User is null. I would bet it is just that windows integrated authentication is not enabled on the live web server or a similar authentication setup issue.
这个问题的解决方案是通过 machine.config 授予完全信任并自动生成架构来创建 mysql_aspnet_membership 提供程序,而不是在数据库中手动创建成员资格表,我认为这可能是创建数据库的有效方法。
后来这个就没有再断过。
The solution for this problem was to create the mysql_aspnet_membership provider by granting full trust through the machine.config and autogenerating the schema, instead of manually creating the membership tables in the database, which I though there could have been a valid way to create the db.
Afterwards, this didn't break anymore.