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

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)系我們修改或刪除,多謝。

主站蜘蛛池模板: 京香在线播放 | 小妇人电影免费完整观看2021 | 小SAO货叫大声点妓女 | 98国产精品人妻无码免费 | 99久久亚洲综合精品 | 乌克兰黄色录像 | 日久精品不卡一区二区 | 男人脱女人衣服吃奶视频 | 亚洲精品免费观看 | 色偷偷在线视频 | 午夜看片福利在线观看 | 纯肉巨黄H爆粗口男男分卷阅读 | 欧美多人群p刺激交换电影 欧美多毛的大隂道 | 久久婷婷色一区二区三区 | 日本动漫henta videos | 媚药调教被撑到合不拢h | 日本漫画母亲口工子全彩 | 香蕉在线播放 | 性美国人xxxxx18 | 最新色导航 | 暖暖高清视频免费 | 亚洲视频免费在线观看 | 天天狠狠色综合图片区 | 亚洲AV精品一区二区三区不卡 | 欧洲vs美洲完整视频 | 亚洲 无码 在线 专区 | 麻豆文化传媒一区二区 | 国产99青草全福视在线 | 99日精品欧美国产 | 视频区 国产 欧美 日韩 | 无遮掩H黄纯肉动漫在线观看星 | 国产成人久久精品激情 | 亚洲AV午夜精品麻豆AV | 在线 国产 欧美 专区 | 久久本道久久综合伊人 | 国产一区在线观看免费 | 国产日韩精品一区二区三区在线 | 操中国老太太 | 亚洲精品无码午夜福利在线观看 | 国产做国产爱免费视频 | jizzjizz3d动漫|