首页 新闻 搜索 专区 学院

FormsAuthenticationTicket 验证失败,页面跳转不了

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-11-28 08:28

登陆代码:

 protected void Button1_Click(object sender, EventArgs e)
        {
            string UserName = txtUserName.Text;
            string PassWord = txtPassWord.Text;
            DataSet ds = new DataSet();
            try
            {
                ds = LoginBusiness.GetTheUser(UserName);
                if (PassWord == ds.Tables[0].Rows[0]["PassWord"].ToString())
                {
                    //Session["UserName"] = UserName;
                    //Session["UserCode"] = ds.Tables[0].Rows[0]["PassWord"].ToString();
                    //Server.Transfer("Index.aspx");
                    List<string> List = new List<string>();
                    string UserStr = string.Empty;
                    List = LoginBusiness.GetSystemFuction(int.Parse(ds.Tables[0].Rows[0]["UserCode"].ToString()));
                    if (List.Count != 0)
                    {
                        //将查询到的功能用“,”连接起来
                        UserStr = List[0].ToString();
                        for (int i = 1; i < List.Count ; i++)
                        {
                            UserStr = UserStr + ","+List[i].ToString();
                        }
                        //UserStr = UserStr + List[List.Count - 1].ToString();//最后一个加入
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                       1,
                       UserName,
                       DateTime.Now,
                       DateTime.Now.AddMinutes(20),
                       true,
                       UserStr,
                       FormsAuthentication.FormsCookiePath);

                        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);//加密

                        HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                        Response.Cookies.Add(authCookie);//写到客户端cookie中

                        Response.Redirect("Index.aspx");
                    }
                    else
                    {
                        Utility.AlertMsg(this,"你还没有权限,请与管理员联系");
                    }
                }
            }
            catch
            {
                Utility.AlertMsg(this,"用户名或密码错误");
            }
        }

 

web.config代码:

    <authentication mode="Forms">
      <forms name="Hstear" loginUrl="Login.aspx" protection="All" path="/" timeout="40" defaultUrl="Index.aspx"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>

Global.asax代码

   protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (HttpContext.Current.User != null)
            {
                if (HttpContext.Current.User.Identity is FormsIdentity)
                {
                    FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                    FormsAuthenticationTicket ticket = id.Ticket;
                    string userData = ticket.UserData;
                    //string[] roles = new string[1];
                    //roles[0] = userData.ToString();
                    string[] roles = userData.Split(',');
                    HttpContext.Current.User = new GenericPrincipal(id, roles);
                }
            }
        }

当我输入正确的账号和密码后,点击登陆按钮,但是页面还是跳转到登陆页面,这是不是说明系统还认为我是匿名用户?我对登陆的代码进行了异步调试没有错无啊,请高手帮解决,解决后在加分,很急

菜鸟至菜的主页 菜鸟至菜 | 初学一级 | 园豆:17
提问于:2011-11-26 23:42
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册