2012-12-01 28 views
0

我正在尝试检查用户身份验证时,我总是得到用户身份验证。这里是我的代码:检查用户身份验证总是结果为真

if(User.Identity.IsAuthenticated) 
{ 
    addProfiledata(); 
} 

即使我登录并注销,此条件始终为真。

我该如何解决这个问题?

+0

您在使用** FormsAuthentication.Signout()**从应用程序注销。 –

+0

你认为他不再认证的地方在哪里? – Thousand

+0

我已经使用了一个LoginControl我做过它自动使用它,我会尝试 –

回答

0

如果你已经定义了用户角色,那么它应该被处理,你正在使用LoginControl,我想你正在处理唱歌与其他登录控制如loginview唱歌,并希望你分配给用户角色。如果这是一个情况下,你可以使用LoginUser_LoggedIn事件

 // suppose if you are willing to redirect a user according to his/her role 
protected void LoginUser_LoggedIn(object sender, EventArgs e) 
     { 
      if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) 
      { 
       // if user in role and authenticated 
       if (Roles.IsUserInRole(LoginUser.UserName, "Developers")) 
       { 
        // add session and redirect to particular page 
        Session.Add("developer", "Developers"); 
        Response.Redirect("../Developers/devAccess.aspx");

  } 
     } 
    } 

0

试试这个:

if(HttpContext.Current.Request.IsAuthenticated) { 

    //put code for Authenticated user 

} 

或者交替

if(User.IsInRole("rolename")) { 

    //put code for Authenticated user 

} 

希望这将帮助!

+0

我已经tryed HttpContext.Current.Request.IsAuthenticated它仍然现在工作里面的方法仍然执行 –

+0

好吧,我想你没有注销。 –