防止用户越过登陆页面:
Global.asax.cs文件中
protected void Session_Start(Object sender, EventArgs e)
{
/* 若用户欲越过登陆页面而直接访问其它页面,将其导航至登陆页面 */ string strFile = this.Context.Request.FilePath.ToString();
string strRoot = Application["RootUrl"].ToString();
if(!strFile.Equals("/"+strRoot+"/Default.aspx"))
{
this.Response.Redirect("/"+strRoot+"/Default.aspx");
}
}
Global.asax.cs文件中
protected void Session_Start(Object sender, EventArgs e)
{
/* 若用户欲越过登陆页面而直接访问其它页面,将其导航至登陆页面 */ string strFile = this.Context.Request.FilePath.ToString();
string strRoot = Application["RootUrl"].ToString();
if(!strFile.Equals("/"+strRoot+"/Default.aspx"))
{
this.Response.Redirect("/"+strRoot+"/Default.aspx");
}
}
<META http-equiv="content-type" content="no-cache">
///
不会的,那是你的Session还在,你可以在注销时删除该Session
我的page2是aspx页,该怎么写啊?
<authentication mode="Forms">
<forms name=".ASPX" loginUrl="page1.aspx" protection="All" timeout="60" path="/">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
end if
没有人有过相同的问题吗?
Session["UserID"]="xxx";//记录已经登陆的用户
RegisterOff.aspx //注销
if (Session.Keys[i]=="UserID")
Session.RemoveAt(i);
page2.aspx
Page_load()
{
if ((string)Session["UserID"]==null)
{
Response.Redirect("page1.aspx?mode=timeout");
}
}
可能是你程序验证逻辑的错误,能否贴出一些代码
if(Session["asdf"]== null)
{
Response.Redirect("登陆页面!");
}
试试看!
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
代码:private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (Session["id"] == null String)||((Stirng)Session["id"] == "0"))
{
Response.Write(PAGE_NOLOG);
}
}
//我是把id设置为0,表示未登录
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (Session["id"] == null )||((Stirng)Session["id"] == "0"))
{
Response.Write(PAGE_NOLOG);
}
}
//我是把id设置为0,表示未登录
是不是要用到JavaScript啊?
<META http-equiv="content-type" content="no-cache">
或者在head与body之间加入
<%response.expires=0 %>
这个不能保证完全有效。我也正在找有没有更好的方法。
{
if (Session["User"].ToString()!="" )
{
Session.Remove("User");
Session.RemoveAll();
Session.Abandon(); }
只是在buttonke点击事件Redirect到其它页面之前先用
Systerm.Web.Security.FormsAuthentication.RedirectFromLoginPage(User_Id,false);就可以了!
注销用Systerm.Web.Security.FormsAuthentication.SignOut();
情
if session("user")=null then
end if