一个asp.net的小网站,有几个页面需要登录后才可以看的我就在登陆页面放了个:
Session["UintName"] = txtUserName.Text;
Response.Redirect("../News.aspx",true);然后在News.aspx里面放了个:
Server.Execute("sn/incs/checkPurview.aspx"); // 此处用户权限验证在checkPurview.aspx里面用了:
if (Session["UintName"] == null)
{
Response.Write("对不起,您没有权限!");
Response.End();
}
现在有个问题, 我登陆转向News.aspx是正常打开了但是一刷新News.aspx就打不开了,变成:“对不起,您没有权限!”
而且其它使用Server.Execute("sn/incs/checkPurview.aspx")也是没有通过验证。这个是什么情况?
Session["UintName"] = txtUserName.Text;
Response.Redirect("../News.aspx",true);然后在News.aspx里面放了个:
Server.Execute("sn/incs/checkPurview.aspx"); // 此处用户权限验证在checkPurview.aspx里面用了:
if (Session["UintName"] == null)
{
Response.Write("对不起,您没有权限!");
Response.End();
}
现在有个问题, 我登陆转向News.aspx是正常打开了但是一刷新News.aspx就打不开了,变成:“对不起,您没有权限!”
而且其它使用Server.Execute("sn/incs/checkPurview.aspx")也是没有通过验证。这个是什么情况?
{
if (TextBox1.Text.Equals(""))
{
Response.Write("<script>alert('用户名不能为空');</script>");
}
else if (TextBox2.Equals(""))
{
Response.Write("<script>alert('密码不能为空');</script>");
}
else
{
string name = TextBox1.Text.Trim().ToString();
string pass = TextBox2.Text.Trim().ToString(); string strWhere = " adminname='" + name + "' and adminpass='" + pass + "' ";
DataSet ds = new DataSet();
ds = bll.GetList(strWhere);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Write("<script>alert('登陆成功');location.href='index.aspx';</script>");
Session["admin"] = name;
}
else
{
Response.Write("<script>alert('登陆失败,请重新输入');</script>");
}
}
}
if (!IsPostBack)
{
if (Session["admin"] == null)
{
// Response.Write("<script>alert('登陆超时');top.location.href='login.aspx';</script>");
Response.Write("<script>alert('登陆超时');window.parent.location.href='login.aspx';</script>"); }
else
{
}
}
你用Inlcude 或者做个用户自定义控件也可以啊。
貌似 Server.Execute,是服务器端执行,运行后,其将创建一个新的会话。
if (!IsPostBack)
{
//你所有的验证代码
}
这样写的话刷新页面不会重复执行page_load里面的代码
跳转后的页面用:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["IsAdmin"] != null)
{
if ((bool)Session["IsAdmin"])
{
HyperLink6.Visible = true;
HyperLink7.Visible = true;
}
else
{
HyperLink6.Visible = false;
HyperLink7.Visible = false;
}
}
}你根据具体情况改改吧
其实没必要这样判断.只需要再读一次
if(session[""]!=null)
{
//已登录了.有session,自己的代码
}
else
{
//未登录...
}