C# 我能否以编程方式防止由于cookie大小而引发400错误?
我的团队维护一套C#应用程序,它们共享一组共同的cookie 最近,我们遇到了这样一种情况:cookie大小变得太大,用户在访问我们的生产站点时开始遇到400错误 我编写了一个小小的webforms应用程序,它将遍历我们的Cookie列表并删除它们,其中不包括我们尝试在Global.asax中读取/写入Cookie的共享代码:C# 我能否以编程方式防止由于cookie大小而引发400错误?,c#,iis-7.5,C#,Iis 7.5,我的团队维护一套C#应用程序,它们共享一组共同的cookie 最近,我们遇到了这样一种情况:cookie大小变得太大,用户在访问我们的生产站点时开始遇到400错误 我编写了一个小小的webforms应用程序,它将遍历我们的Cookie列表并删除它们,其中不包括我们尝试在Global.asax中读取/写入Cookie的共享代码: foreach (var c in cookieList) { HttpCookie cu
foreach (var c in cookieList)
{
HttpCookie currentUserCookie = HttpContext.Current.Request.Cookies[c];
if (currentUserCookie != null)
{
HttpContext.Current.Response.Cookies.Remove(c);
currentUserCookie.Expires = DateTime.Now.AddDays(-10);
currentUserCookie.Value = null;
HttpContext.Current.Response.SetCookie(currentUserCookie);
}
}
然而,我们网站上的所有页面仍然抛出错误。我们能找到的唯一解决方案是让用户手动删除他们的cookie
我们是否可以触发从服务器端删除cookie,从而避免用户手动清除cookie的麻烦?我们正在使用IE11和Chrome 54。这一行尝试更新现有cookie(它已从响应中删除) 试试这个
foreach (var c in cookieList)
{
HttpCookie currentUserCookie = HttpContext.Current.Request.Cookies[c];
if (currentUserCookie != null)
{
HttpContext.Current.Response.Cookies.Remove(c);
currentUserCookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(currentUserCookie);
}
}
foreach (var c in cookieList)
{
HttpCookie currentUserCookie = HttpContext.Current.Request.Cookies[c];
if (currentUserCookie != null)
{
HttpContext.Current.Response.Cookies.Remove(c);
currentUserCookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(currentUserCookie);
}
}