1.Session的清除
Session.Clear();
Session.Abandon();            
//居多
Session.RemoveAll();

2.Session失效后自动跳转
(1). load函数中实现

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["UserID_P"]==null)   //防session过期
{
Response.Write(
"<script language='javascript'>window.parent.location.href='../login.aspx';</script>");
}

}


=============================================================
(
2).在每页面里添加的内容:

<%if session("user")="" then response.redirect"login.asp"%>


=============================================================
(
3)在Web.Config文件中设置:

<authentication mode="Forms">              
    
<forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
</authentication>
<authorization>
    
<deny users="?"/>
</authorization>

===============================================================
(
4)Session_Start里写:
protected void Session_Start(Object sender, EventArgs e)
{

Response.Redirect(
"登陆的页面");

}

posted on 2008-07-04 15:37  apple  阅读(257)  评论(0)    收藏  举报