2015-04-08 28 views
1

我有一封電子郵件確認控制器,我張貼到。我如何刪除mvc的會話和cookie 5

當發生這種情況時,我需要註銷,清除與用戶有關的會話和cookie ...這是因爲當他們確認他們的電子郵件時,我需要一個按鈕以使用戶重新發送確認電子郵件。

我這樣做是這樣的:

[HttpPost] 
[Authorize] 
public async Task<ActionResult> ReSendEmailConfirmation(string userID) 
{ 
    await this.SendEmailConfirmation(userID); 

    //Log off to prevent stale user session 
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 
    Session.Clear(); 
    Session.Abandon(); 
    Response.Cookies.Clear(); 

    return RedirectToAction("ReSendEmailConfirmation"); // I am logged out okay, but when i goto my email... click the confirmation link, then log back in... it still says my email is not confirmed. If i shut my browser down, it will then update. 
} 

的問題是,即使經過了這一切......

當我重新登錄,但它仍然表示,未確認電子郵件,.. 。即使它在數據庫中...

如何完全清除用戶會話?

回答

1

Session.Clear將清除所有會話。 而Response.Cookies.Clear將清除所有的cookies。 ,你可以用[NoCache]來修飾你的動作,以防止它被緩存

+0

我試過Cookies.Clear,仍然沒有運氣..我會嘗試NoCache。這是什麼名字空間? – Jimmyt1988

+0

應該在system.web.mvc ... – Aram

+0

你可以在這裏找到相關的問題 - [invalidate-old-session-cookie-asp-net-identity](https://stackoverflow.com/questions/34020730/invalidate-老會話cookie的ASP淨身份) – krypru