asp如何实现判断用户是否登录, 如果登录则显示 信息联系方式,如果未登录就提示请登录后查看
2个回答
展开全部
用 Session存储登录名
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] != null)
{
this.lblDenglu.Text = Session["userName"] + "欢迎您!";
this.btnZhuXiao.Visible = true;
}
else
{
this.btnZhuXiao.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
this.user.Enabled = false;
this.pass.Enabled = false;
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您已经登录过!如果想登录其他号码请先注销!')</script>");
}
else
{
User user;
if (UserManager.AdminLogin(this.txtUser.Text, this.txtPass.Text, out user))
{
string strRedirect;
strRedirect = Request["ReturnUrl"];
System.Web.Security.FormsAuthentication.SetAuthCookie(user.UserName, true);
if (strRedirect == null)
{
if (user.Status == 0)
{
Session["userName"] = user.UserName;
Response.Redirect("newsList.aspx");
}
else if (user.Status == 1)
{
Session["userName"] = user.UserName;
Response.Redirect("~/Admin/ListAllUsers.aspx");
}
}
//Response.Redirect(strRedirect);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名或者密码错误!');</script>");
}
}
}
不在html里面写,写在asp界面的后台代码里面
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] != null)
{
this.lblDenglu.Text = Session["userName"] + "欢迎您!";
this.btnZhuXiao.Visible = true;
}
else
{
this.btnZhuXiao.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
this.user.Enabled = false;
this.pass.Enabled = false;
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您已经登录过!如果想登录其他号码请先注销!')</script>");
}
else
{
User user;
if (UserManager.AdminLogin(this.txtUser.Text, this.txtPass.Text, out user))
{
string strRedirect;
strRedirect = Request["ReturnUrl"];
System.Web.Security.FormsAuthentication.SetAuthCookie(user.UserName, true);
if (strRedirect == null)
{
if (user.Status == 0)
{
Session["userName"] = user.UserName;
Response.Redirect("newsList.aspx");
}
else if (user.Status == 1)
{
Session["userName"] = user.UserName;
Response.Redirect("~/Admin/ListAllUsers.aspx");
}
}
//Response.Redirect(strRedirect);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名或者密码错误!');</script>");
}
}
}
不在html里面写,写在asp界面的后台代码里面
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询