这个是我在登陆页面里写的
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!Object.Equals(Request.Cookies["username"], null))
{
/*读取保存用户名的cookie信息,此信息保存在客户端,方便管理员减少信息输入*/
HttpCookie userNameCookie = Request.Cookies["username"];
this.txtUser.Text = userNameCookie.Value;
}
}
}
然后再登陆的主窗体里写的
protected void Page_Load(object sender, EventArgs e)
{
/*根据session变量username是否已经建立判断管理员是否登陆了系统,其他操作页面类似*/
if (Session["username"] == null)
{
Response.Redirect("~/admin/main/Login.aspx");
}
}现象是怎么登陆就一个劲的在登陆页面里显示了,不跳转到主页面了
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!Object.Equals(Request.Cookies["username"], null))
{
/*读取保存用户名的cookie信息,此信息保存在客户端,方便管理员减少信息输入*/
HttpCookie userNameCookie = Request.Cookies["username"];
this.txtUser.Text = userNameCookie.Value;
}
}
}
然后再登陆的主窗体里写的
protected void Page_Load(object sender, EventArgs e)
{
/*根据session变量username是否已经建立判断管理员是否登陆了系统,其他操作页面类似*/
if (Session["username"] == null)
{
Response.Redirect("~/admin/main/Login.aspx");
}
}现象是怎么登陆就一个劲的在登陆页面里显示了,不跳转到主页面了
我不太会啊,那用Session我在登陆页面怎么写,在页面也要怎么弄呢?
{}
BasePage中判断
能多写点吗?在登陆中怎么放到Session中,在主页页面中 怎么判断是否登陆
if(Session["UserInfo"]!=null){//主页面};
else
跳转登录以后你的页面都继承BasePage
我在登陆页面写:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["username"] = txtUser.Text();
}
}
把用户放到Session中
在主界面写:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("~/admin/main/Login.aspx");
}
}
做这个判断没反应啊
{
if (!IsPostBack)
{
if (!Object.Equals(Session["username"], null))
{
/*读取保存用户名的cookie信息,此信息保存在客户端,方便管理员减少信息输入*/
Session["username"]="要放入的用户名";
this.txtUser.Text = Session["username"].ToString();
}
}
{
if (!IsPostBack)
{
if (Session["username"]!=null&&Session["username"].tostring()!="")
{
Session["username"]==txtUser.Text
Response.Redirect("~/admin/main/Main.aspx"); }
else
{
Response.Redirect("~/admin/main/Login.aspx");
}
}
}
Login.aspx.cs页面一个文本框,一个按钮
按钮Click事件
{
Session["UserName"]=this.txtUserName.Text;
this.Response.Redirect("index.aspx");
}
index.aspx.cs代码
Page_Load事件
{
if(Session["UserName"]==null)
{
跳转到登录不就OK了
}
}
1.用户点击登录时:
将用户ID或者用户名写进Session
Session["UserID"]="用户ID或者用户名";
2.判断是否登录protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(Session["UserID"]==null)
{
//用户没有登录进行的操作,如页面跳转等
}
}
}
Cookie:
如果写进的是cookie, 则用cookie判断
if (Request.Cookies["UserID"] != null)
{}