欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET網(wǎng)站管理系統(tǒng)退出 清除瀏覽器緩存,Session的代碼

 更新時(shí)間:2012年05月17日 15:37:44   作者:  
管理系統(tǒng)退出登陸后,將網(wǎng)址重新輸入后還會(huì)看到用戶登陸后的界面,為了解決這個(gè)問(wèn)題,我采用了以下方法,需要的朋友可以參考下
1、在系統(tǒng)登陸成功時(shí)記錄登陸的用戶名、密碼等信息(登陸功能的部分代碼)
復(fù)制代碼 代碼如下:

Session["id"] = user.id.ToString();
Session["name"] = user.name.ToString();
Session["pwd"] = user.password.ToString();
Session["time"] = user.LoginTime.ToString();
Session["authority"] = user.limits.ToString();

2、在管理系統(tǒng)的每個(gè)頁(yè)面中加入以下代碼,在頁(yè)面加載時(shí)判斷session的值是否為空
復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] == null || Session["name"] == null || Session["time"] == null || Session["authority"] == null || Session["pwd"] == null)
Response.Redirect("~/Login.aspx", true);
if (!IsPostBack)
{
。。。。。。
}
}

3、在點(diǎn)擊“退出系統(tǒng)”執(zhí)行的事件中加入session清空的代碼和瀏覽器緩存清空的代碼
復(fù)制代碼 代碼如下:

public void Clear(object sender, EventArgs e)
{
Session["id"] = null;
Session["name"] = null;
ClearClientPageCache();
Response.Redirect("~/Login.aspx");
}
public void ClearClientPageCache()
{
//清除瀏覽器緩存
  Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
}

由于我的“退出系統(tǒng)”時(shí)用HTML的<a>標(biāo)簽寫(xiě)在母版頁(yè)中的,因此上面的代碼是寫(xiě)在母版頁(yè)的.cs文件中的。
母版頁(yè)代碼:
復(fù)制代碼 代碼如下:

<a class="atop" target="_self" <SPAN style="BACKGROUND-COLOR: #ff0000">runat="server" onserverclick</SPAN> ="Clear" >退出系統(tǒng)</a>

================================================================================================
之前的版本一直不能實(shí)現(xiàn)功能,糾結(jié)了很久,沒(méi)有找出問(wèn)題所在,把剛開(kāi)始執(zhí)行錯(cuò)誤的代碼貼出來(lái),同時(shí)也我把自己的認(rèn)為錯(cuò)誤的地方貼出來(lái),希望大家批評(píng)指正。
這個(gè)版本的錯(cuò)誤是:登陸成功后進(jìn)入主頁(yè)面,然后再點(diǎn)擊進(jìn)入其他頁(yè)面時(shí)都無(wú)法進(jìn)入,都會(huì)跳到登陸界面。
我的思考:
      1、我在跟蹤調(diào)試時(shí)發(fā)現(xiàn),每次頁(yè)面加載時(shí)都會(huì)自動(dòng)執(zhí)行母版頁(yè).cs文件中的Clear()方法,因此不能通過(guò)其他頁(yè)面Page_Load()方法中 的 if (Session["id"] == null || Session["name"] == null || Session["time"] == null || Session["authority"] == null || Session["pwd"] == null) Response.Redirect("~/Login.aspx", true);
      2、我的疑問(wèn)在于,Clear()方法明明是點(diǎn)擊后才執(zhí)行的,為什么每次加載頁(yè)面的時(shí)候都自動(dòng)執(zhí)行?
      3、我考慮錯(cuò)誤的原因是客戶端和服務(wù)器端執(zhí)行方法的不同,然后在網(wǎng)上找了關(guān)于onclick,和onserverclick的區(qū)別,但是對(duì)他們的理解還不是很清楚。希望大家能夠交流一下。
關(guān)于onclick,和onserverclick的區(qū)別參見(jiàn):http://www.dbjr.com.cn/article/30313.htm
剛開(kāi)始前臺(tái)代碼用的是(母版頁(yè)前臺(tái)代碼):
復(fù)制代碼 代碼如下:

<a href="~/Login.aspx" class="atop" target="_self" onclick=“clear()”>賬戶信息</a>
<script>
  function clear()<BR>  {<BR>    <%Clear();%><BR>  }
</script>

母版頁(yè)后臺(tái)代碼
復(fù)制代碼 代碼如下:

public void Clear()
{
Session["id"] = null;
Session["name"] = null;
}

相關(guān)文章

最新評(píng)論