手动删除asp.net身份验证cookie

Sha*_*ean 6 asp.net

如何手动删除子域为asp.net身份验证设置的cookie?

饼干已经开启setter.test.com;

<authentication mode="Forms">
    <forms domain="test.com" loginUrl="Default.aspx" protection="All" path="/" requireSSL="false" timeout="45" name=".ASPXAUTH" slidingExpiration="true" defaultUrl="Default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
</authentication>
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中getter.test.com,这是我的注销代码(删除该cookie):

public ActionResult LogOut()
{
        //Manually remove the cookie created by 3rd party authentication
            if (Request.Cookies[".ASPXAUTH"] != null)
            {
                HttpCookie myCookie = new HttpCookie(".ASPXAUTH");
                myCookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(myCookie);
            }
}
Run Code Online (Sandbox Code Playgroud)

这不起作用.

Mit*_*ers 4

一个小小的改变,你就可以开始了。

public ActionResult LogOut()
{
    //Manually remove the cookie created by 3rd party authentication
        if (Request.Cookies[".ASPXAUTH"] != null)
        {
            HttpCookie myCookie = new HttpCookie(".ASPXAUTH");
            myCookie.Expires = DateTime.Now.AddDays(-1d);
            myCookie.Domain = "test.com";
            Response.Cookies.Add(myCookie);
        }
}
Run Code Online (Sandbox Code Playgroud)

您必须确保两者的域设置相同。