天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

Asp.net 基于Cookie簡易的權限判斷

寫入Cookie頁面,創建cookie后,設置cookie屬性,并添加到Response.Cookies中讀取cookie,利用cookie的名字或索引從Request.Cookies中取得改寫Cookie,先創建一個同名的cookie,讀取Request中同名的cookie,把讀取cookie的屬性值付給新的對象,加入到Response.Cookies中創建一個BasePage頁面,其他的頁面繼承自這個頁面,把權限判斷的代碼有單個頁面的Page_Load轉移到BasePage的PreLoad中,下面是BasePage的主要代碼
復制代碼 代碼如下:
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技術Asp.net 基于Cookie簡易的權限判斷,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 日本十八禁无遮拦啪啪漫画 | 视频成人永久免费看 | 国产成人精品免费视频软件 | 亚洲精品视频免费看 | 国产大片51精品免费观看 | 久久re视频精品538在线 | 99re热精品视频国产免费 | WWW国产精品人妻一二三区 | 欧美精品成人一区二区在线观看 | 韩国精品韩国专区久久 | 丰满老熟女白浆直流 | 国产MD视频一区二区三区 | 久久久久久久久久久福利观看 | 日本阿v在线资源无码免费 日本阿v片在线播放免费 | 国产精品久久久亚洲偷窥女厕 | 色多多污污版免费下载安装 | 亚洲精品国产AV成人毛片 | 羞羞麻豆国产精品1区2区3区 | 熟妇久久无码人妻AV蜜桃 | 久色乳综合思思在线视频 | 轻轻挺进女教师的身体 | 曰本女人牲交视频免费 | 涩里番app黄版网站 色综合伊人色综合网站中国 | 亚洲国产中文字幕在线视频综合 | 成人毛片免费观看视频大全 | 成 人 免费 黄 色 网站无毒下载 | 在线免费视频国产 | xxxxx69hd杨幂| 精品久久久久中文字幕加勒比东京热 | 国产中文视频无码成人精品 | 成人18视频在线 | 2022久久精品国产色蜜蜜麻豆 | 麻豆AV福利AV久久AV | 清冷受被CAO的合不拢 | 中文字幕在线观看亚洲日韩 | 曰本真人00XX动太图 | 免费国产成人高清在线看软件 | 久拍国产在线观看 | 啪啪后入内射日韩 | 欧美国产精品久久久乱码 | 日本2021免费一二三四区 |