以下是登录按钮事件下的代码:
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页面正确的获取当前登录用户的用户名和所其所属的角色。谢谢诸位的回答。
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页面正确的获取当前登录用户的用户名和所其所属的角色。谢谢诸位的回答。
取到的值是空的。
各位高手请帮忙解答一下吧,拜托各位了。
有些信息保存到FormsIdentity类的实例里,
在使用的时候就可以context.user.identity.name提取出来。
我又改成这样了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");
}接下来怎么做?真的就没有人会吗?