激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - Asp.net 基于Cookie簡易的權(quán)限判斷

Asp.net 基于Cookie簡易的權(quán)限判斷

2019-07-03 17:24ASP.NET之家 ASP.NET教程

基于Cookie簡易的權(quán)限判斷代碼,需要的朋友可以參考下。

寫入Cookie頁面,創(chuàng)建cookie后,設(shè)置cookie屬性,并添加到Response.Cookies中讀取cookie,利用cookie的名字或索引從Request.Cookies中取得改寫Cookie,先創(chuàng)建一個(gè)同名的cookie,讀取Request中同名的cookie,把讀取cookie的屬性值付給新的對象,加入到Response.Cookies中創(chuàng)建一個(gè)BasePage頁面,其他的頁面繼承自這個(gè)頁面,把權(quán)限判斷的代碼有單個(gè)頁面的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; 


延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日韩中文字幕在线视频 | 久草欧美 | 娇妻被各种姿势c到高潮小说 | 国产小视频在线 | 色综合久久久久久久久久久 | 久久精品a一级国产免视看成人 | 精品成人av一区二区三区 | 久久久涩| 色妞色视频一区二区三区四区 | 精品一区免费 | 蜜桃视频网站在线观看 | 亚洲成人福利 | 欧美高清另类自拍视频在线看 | 中文字幕欧美在线 | 欧美成人se01短视频在线看 | 色人久久 | 小情侣嗯啊哦视频www | av色哟哟| 欧美大穴 | 韩国三级日本三级香港三级黄 | 久久超碰99| 国产99页 | av电影在线观看网站 | 日本一区二区三区高清不卡 | 一区二区三区视频在线播放 | 国产一级毛片国语版 | 欧美一二区视频 | 少妇一级淫片免费放4p | a视频在线播放 | 激情亚洲一区二区 | 日本免费a∨ | 毛片大全在线观看 | 九九热视频在线免费观看 | 国产一区二区三区手机在线 | 黄色国产在线观看 | 99精品视频一区二区 | 欧美一级做性受免费大片免费 | 国产在线一级片 | 亚洲成人福利网站 | 日韩在线视频导航 | 99re热精品视频 |