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

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

主站蜘蛛池模板: 丰满艳妇亲伦 | 岛国片免费在线观看 | 国产亚洲视频中文字幕 | 黄色免费网址在线观看 | 老司机福利视频一区在线播放 | 在线视频久久只有精品第一日韩 | silk118中文字幕无删减 | 99视频这里只有精品国产 | 末成年美女黄网站色大片连接 | 亚洲国产AV无码综合在线 | 亚洲色无码播放 | 青青青青久久久久国产的 | WWW国产精品人妻一二三区 | 亚洲精品视频免费 | 高清一区二区亚洲欧美日韩 | 黑人特黄AA完整性大片 | 阿离被扒开双腿疯狂输出 | 国产WW高清大片免费看 | MMM日本兽交 | 中文字幕一区二区三区在线播放 | 好湿好滑好硬好爽好深视频 | 午夜成a人片在线观看 | 精品少妇高潮蜜臀涩涩AV | 韩国伦理三级 | 亚洲免费黄色片 | 亚洲精品综合在线影院 | 久久综合狠狠综合狠狠 | 91系列在线观看免费 | 日本高清无卡码一区二区久久 | 男人网站在线 | 俄罗斯9一14 young处 | 久久99AV无色码人妻蜜 | 欧美乱子YELLOWVIDEO | 尿了么app | 日本浴室日产在线系列 | 欧美精品成人一区二区在线观看 | 欧美日韩无套内射另类 | 久久re视频精品538在线 | 精品视频在线观看视频免费视频 | 91综合精品网站久久 | 丁香美女社区 |