How do I manually delete a cookie in asp.net MVC 4

后端 未结 2 1326
温柔的废话
温柔的废话 2020-12-09 15:16

I need to delete authentication cookie manually (Instead of using FormsAuthentication.SignOut whcih for some reasons does not work). I tried

System.Web.Http         


        
2条回答
  •  一生所求
    2020-12-09 15:46

    Try:

    if ( Request.Cookies["MyCookie"] != null )
    {
        var c = new HttpCookie( "MyCookie" );
        c.Expires = DateTime.Now.AddDays( -1 );
        Response.Cookies.Add( c );
    }
    

    More information on MSDN.

提交回复
热议问题