0

我正在使用表單身份驗證來驗證和授權我的網站中的請求。無法完全從網站註銷使用表單身份驗證

這裏是登錄代碼:

var objLogin = new LoginModel { Email = model.Email, Password = CommonMethod.Encryptdata(model.Password) }; 
var UserDetail = Users.LoginUser(objLogin); 
if (UserDetail.ErrorMessage == "SuccessLogin") 
{ 
    var UserData = UserDetail.UserId + "," + UserDetail.UserRole + "," + UserDetail.Email + "," + UserDetail.FirstName + "," + UserDetail.LastName; 
    DateTime expirydate = DateTime.Now.AddDays(10); 
    var Ticket = new FormsAuthenticationTicket(1, UserDetail.Email, DateTime.Now, expirydate, true, UserData, FormsAuthentication.FormsCookieName); 
    string hashCookies = FormsAuthentication.Encrypt(Ticket); 
    var Cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies); 
    Response.Cookies.Add(Cookie); 
    ViewBag.InActiveStatus = ""; 

    //Code for expiration 
    if (Ticket.IsPersistent) 
    { 
     Cookie.Expires = Ticket.Expiration; 
    } 

    if (!string.IsNullOrEmpty(returnUrl)) 
    return Redirect(returnUrl); 
} 

我使用永久性Cookie。

用來註銷該網站包含下面的代碼的方法:

FormsAuthentication.SignOut(); 

Session.Abandon(); 
Session.Clear(); 
Session.RemoveAll(); 

string[] myCookies = Request.Cookies.AllKeys; 

foreach (string cookie in myCookies) 
{ 
    Response.Cookies[cookie].Expires = DateTime.Now.AddYears(-1); 
} 

return RedirectToAction("Login", "Account"); 

我面對的是退出後,我能夠上網首頁控制器 頁面普遍存在的問題。我已經在所有家庭控制器方法上實施了授權(角色=「用戶」)。

[Authorize(Roles = "user")] 
public ActionResult Index() 

但我不能夠上網衝浪其他控制器.eg 在挑戰控制器下面的方法頁面(家庭以外):

[Authorize(Roles = "user")] 
public ActionResult MyChallenges() 

的問題被解決,當我強行清理瀏覽器從用戶體驗的角度來看,這不推薦給普通用戶使用。

請說出爲什麼會發生這種情況?提前致謝 !

回答

0

嗨Stackoverflow專家

我仍在等待我的答案!

謝謝 Imastu

相關問題