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

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

主站蜘蛛池模板: 国产亚洲精品第一区香蕉 | 两个客户一起吃我的奶 | 姉调无修版ova国语版 | 亚洲人成影院在线播放 | 老司机亚洲精品影院在线观看 | 久久精品成人免费网站 | 国产AV电影区二区三区曰曰骚网 | 国产成人精品免费视频软件 | 4399亚洲AV无码V无码网站 | 久久国产精品福利影集 | 激情女人花 | 蜜桃人妻无码AV天堂三区 | 国产69精品久久久久无码麻豆 | 视频一区国产 | 97色伦图区97色伦综合图区 | 日韩精品一区二区亚洲AV观看 | 国产欧美日韩视频怡春院 | 日本漫画大全无翼乌 | 美女张开腿让男生桶动态图 | 无码人妻丰满熟妇啪啪网不卡 | 亚洲99精品A片久久久久久 | 教室里的激情电影 | 亚洲成人精品久久 | 男人插曲女人下生免费大全 | 亚洲精品人成电影网 | 歪歪爽蜜臀AV久久精品人人槡 | 日本二区三区欧美亚洲国 | 亚洲一区精品伊人久久伊人 | 最近日本MV字幕免费观看在线 | 网址在线观看你懂我意思吧免费的 | 国产AV综合手机在线观看 | 含羞草在线免费观看 | 囯产精品一品二区三区 | 婷婷久久综合九色综合伊人色 | 国产麻豆福利AV在线观看 | 久久青青热| 手机看片一区二区 | 37大但人文艺术A级都市天气 | 国产在线精品亚洲二品区 | 99久久国产综合精品国 | 精品无码无人网站免费视频 |