天天躁日日躁狠狠躁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簡易的權限判斷,轉載需保留來源!

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

主站蜘蛛池模板: 老司机福利视频一区在线播放 | 打扑克床上视频不用下载免费观看 | 中文字幕中文字幕永久免费 | 国产免国产免费 | 找老女人泻火对白自拍 | 亚洲人成电影网站色2017 | 亚洲区 bt下载 | 色综合久久五月 | 97在线视频网站 | 婷婷开心激情综合五月天 | 国产精品麻豆a在线播放 | 免费毛片在线播放 | 国产精品久久久久无码AV色戒 | 午夜福到在线2019 | 国产成人在线免费观看 | www.av在线| 亚洲一区在线视频观看 | 老师扒开尿口男生摸尿口 | 亚洲H成年动漫在线观看不卡 | 精品免费久久久久久影院 | 亚洲AV国产国产久青草 | 一级无毛片 | 国产69精品麻豆久久久久 | 无码任你躁久久久久久老妇双奶 | 日日操日日射 | 高清无码中文字幕在线观看视频 | 国产亚洲一区二区三区啪 | 99re久久这里只有精品 | 小小水蜜桃免费影院 | 亚洲国产成人精品无码区5566 | 人妻体内射精一区二区 | 亚洲AV 日韩 国产 有码 | 一个人的视频全免费在线观看www | 97人人超碰国产精品最新蜜芽 | 短篇合集纯肉高H深陷骚 | jzz大全18 | 亚洲高清无在码在线电影 | 欧美精品色婷婷五月综合 | 一个人的免费完整在线观看HD | 我强进了老师身体在线观看 | 97视频精品|