一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

Asp.net 基于Cookie簡(jiǎn)易的權(quán)限判斷

寫(xiě)入Cookie頁(yè)面,創(chuàng)建cookie后,設(shè)置cookie屬性,并添加到Response.Cookies中讀取cookie,利用cookie的名字或索引從Request.Cookies中取得改寫(xiě)Cookie,先創(chuàng)建一個(gè)同名的cookie,讀取Request中同名的cookie,把讀取cookie的屬性值付給新的對(duì)象,加入到Response.Cookies中創(chuàng)建一個(gè)BasePage頁(yè)面,其他的頁(yè)面繼承自這個(gè)頁(yè)面,把權(quán)限判斷的代碼有單個(gè)頁(yè)面的Page_Load轉(zhuǎn)移到BasePage的PreLoad中,下面是BasePage的主要代碼
復(fù)制代碼 代碼如下:
public class BasePage : System.Web.UI.Page
{
private string pageName;
public BasePage()
{
this.Page.PreLoad += Page_Load;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Uri r = this.Request.Url;
pageName = r.AbsolutePath;
if (NeedToCheck())
{
if (!HasAuthentication())
{
HttpContext.Current.Response.Redirect("NoAuthenticationPage.ASPx");
}
}
}
}
private bool NeedToCheck()
{
if (pageName.Contains("NoAuthenticationPage.ASPx") || pageName == "Login.ASPx" )
{
return false;
}
return true;
}
private bool HasAuthentication()
{
//look into the config file or database,to see whether this page is in the allow accessing list of the role or not;
//the signature of the function is like this
//QueryInConfig(m_UserRole,pageName);
if (pageName.Contains("Default3.ASPx") && UserRole == "2")
{
return false;
}
return true;
}
protected HttpCookie _RequestCookie;
protected HttpCookie _ResponseCookie;
private bool b_IsNewCookie = true;
public string UserRole
{
get
{
return GetCookieValue("UserRole");
}
set
{
SetCookieValue("UserRole", value);
}
}
public string UserName
{
get
{
return GetCookieValue("UserName");
}
set
{
SetCookieValue("UserName", value);
}
}
protected void SetCookieValue(string name, string value)
{
SetResponseCookie();
_ResponseCookie[name] = value;
}
private string GetCookieValue(string name)
{
SetReqeustCookie();
if (_RequestCookie != null)
{
return _RequestCookie[name];
}
return null;
}
protected void SetReqeustCookie()
{
_RequestCookie = HttpContext.Current.Request.Cookies["Cookie_Name"];
}
protected void SetResponseCookie()
{
if (b_IsNewCookie)
{
HttpContext.Current.Response.Cookies.Remove("Cookie_Name");
_ResponseCookie = new HttpCookie("Cookie_Name");
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 2, 0, 0);
_ResponseCookie.Expires = dtNow + tsMinute;
_ResponseCookie["UserRole"] = UserRole;
_ResponseCookie["UserName"] = UserName;
HttpContext.Current.Response.Cookies.Add(_ResponseCookie);
b_IsNewCookie = false;
}
}
}

AspNet技術(shù)Asp.net 基于Cookie簡(jiǎn)易的權(quán)限判斷,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲一区二区三区高清视频 | 五月天婷婷一区二区三区久久 | 我被黑人巨大开嫩苞在线观看 | 亚洲综合色色图 | 色偷偷人人澡久久天天 | 97一区二区三区 | 麻豆精品国产自产在线 | 一级爱爱片一级毛片-一毛 一级爱做片免费观看久久 一级不卡毛片 | 亚洲成人第一页 | 国产欧美在线亚洲一区刘亦菲 | 一区二区三区成人 | 91成品视频| 色视频免费看 | 国产小视频在线高清播放 | 成人在线观看午夜 | 欧美成人免费一级人片 | 唐人社电亚洲一区二区三区 | 日本vs欧美一区二区三区 | 美女扒开屁股给男人看无遮挡 | 亚州综合激情另类久久久 | 性欧美午夜高清在线观看 | 亚洲激情综合网 | 欧美成人禁片在线www | 国产小视频在线 | 欧美在线观看黄色 | 亚洲 欧美 在线观看 | 国产不卡一区二区三区免费视 | 欧美成成人免费 | 热久久99影院 | 亚洲欧美日韩在线2020 | 国产欧美亚洲三区久在线观看 | 视频二区在线观看 | 综合色在线 | 国产高清在线精品 | 国产美女精品三级在线观看 | 亚洲成人一区二区 | 精品国产亚洲人成在线 | 在线观看91香蕉国产免费 | 国产精品久久久久影院色 | 日本无吗免费一二区 | 美女激情网站 |