我有一個我正在處理的asp.net MVC應用程序,並且我編寫了一個自定義actionfilter以基於在登錄時設置的授權級別過濾掉某些控制器操作,並存儲在加密的cookie與formsauthentication cookie一起,兩個cookie被設置爲具有相同的到期時間,但由於某種原因,在空閒時間之後授權cookie值變爲空白,我還沒有能夠調試並在行爲中捕獲它,但它就這樣消失Cookie值在Cookie過期之前過期
我actionfilter代碼如下所示:
string usersRole = "";
if (filterContext.HttpContext.Session["role"] != null)
usersRole = filterContext.HttpContext.Session["role"].ToString();
else if (filterContext.HttpContext.Response.Cookies["ArisPortalCookie"].Value != null)
{
usersRole = filterContext.HttpContext.Response.Cookies["ArisPortalCookie"].Value;
filterContext.HttpContext.Session["role"] = usersRole;
}
string encryptedRole = EncryptionHelper.Encrypt(RoleToCheckFor);
if (encryptedRole == usersRole || usersRole == EncryptionHelper.Encrypt("Admin")) //if the user's role and role required match, we have success
{
//now we break down the response action based on what role was required
if (RoleToCheckFor == "Admin")
{
}
else if (RoleToCheckFor == "Tech" || RoleToCheckFor == "Admin")
{
}
else if (RoleToCheckFor == "Physician" || RoleToCheckFor == "Admin")
{
}
}
else
{
filterContext.Result = new ViewResult
{
ViewName = "NoAuth",
ViewData = filterContext.Controller.ViewData,
TempData = filterContext.Controller.TempData
};
}
讀取值(管道格式)發現了一個可能的問題,我的應用程序存儲它出現時期滿 – Jimmy 2009-09-23 15:24:11