asp.net如何刪除cookie

要刪除cookie值,要如何動手做呢?

以C#為例

//先判斷是否有名為UserSettings的cookie存在
if (Request.Cookies["UserSettings"] != null)
{ 
    HttpCookie myCookie = new HttpCookie("UserSettings");//取得cookie    
    myCookie.Expires = DateTime.Now.AddDays(-1d);//設定cookie的到期日為已過期 
    Response.Cookies.Add(myCookie);//將cookie變動寫回client端
}

出處:How To : Delete a cookie

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s