System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Domain = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString().ToLower();
System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Value = tokenID.ToString();
System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Path = "~/";
System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Expires = DateTime.Now.AddDays(7);
Run Code Online (Sandbox Code Playgroud)
现在,当用户点击注销以使该cookie被销毁时,我将在我的Web应用程序中执行哪些代码?
注意我已经尝试过,没有评论线,也没有工作:
//System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Domain = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString().ToLower();
//System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Value = tokenID.ToString();
//System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Path = "~/";
System.Web.HttpContext.Current.Response.Cookies["ssocookies"].Expires = DateTime.Now.AddDays(-1);
Run Code Online (Sandbox Code Playgroud)
我做的是再次设置它,过去的空白值和失效日期:
var context = System.Web.HttpContext.Current;
context.Response.Cookies["ssocookies"].Domain = context.Request.ServerVariables["SERVER_NAME"].ToString().ToLower();
context.Response.Cookies["ssocookies"].Value = "";
context.Response.Cookies["ssocookies"].Path = "~/";
context.Response.Cookies["ssocookies"].Expires = DateTime.Now.AddDays(-1);
Run Code Online (Sandbox Code Playgroud)