以下是登录按钮事件下的代码:
string username = txtUserName.Text.Trim();
        string password = txtPassword.Text.Trim();
        bool loginFg = Membership.ValidateUser(username,password);
        
        if (loginFg)
        {
            
            Response.Redirect("~/manage/default.aspx");
        }
        else
        {
            lblLoginMsg.Text = "登录失败。用户名或密码错误。";
        }登录成功后页面跳转到default.aspx,在default.aspx页面的Page_Load事件下有如下代码string username1 = HttpContext.Current.User.Identity.Name;
        string username2 = Context.User.Identity.Name;
        bool roleChk = HttpContext.Current.User.IsInRole("admin");
        if (roleChk)
        {
            Response.Write("you are welcome.");
        }
        else
        {
            Response.Redirect("~/error.aspx");
        }我登录用的用户名是aaa,属于角色admin,但是为什么取得的username1和username2都不是aaa呢,
而是我的计算机名和SQL server名的组合。
我的问题是:如何能在default.aspx页面正确的获取当前登录用户的用户名和所其所属的角色。谢谢诸位的回答。

解决方案 »

  1.   

    呵呵,windows身份认证。看看你的web.config<authentication mode="Forms"/>里面的mode值是不是被设置为了"Windows"了.
      

  2.   

    我试过了,结果是string username2 = Context.User.Identity.Name;
    取到的值是空的。
    各位高手请帮忙解答一下吧,拜托各位了。
      

  3.   

    在forms验证时对FormsIdentity类的使用,
    有些信息保存到FormsIdentity类的实例里,
    在使用的时候就可以context.user.identity.name提取出来。
      

  4.   

    可以用session来保存登陆用户名,再在default.aspx的Page_Load事件里面去调用session
      

  5.   


    我又改成这样了string username = "1749";
            string pwd = "111111";
            bool loginChk = Membership.ValidateUser(username, pwd);
            if (loginChk)
            {
                FormsAuthenticationTicket fc = new FormsAuthenticationTicket(username,false,30);
                FormsIdentity f = new FormsIdentity(fc);
                
                Response.Redirect("~/admin/admin.aspx");
            }
            else
            {
                Response.Write("Error");
            }接下来怎么做?真的就没有人会吗?