Как установить значение атрибута samesite в файле cookie __RequestVerificationToken_Lw__
У меня есть токен защиты от подделки (@Html.AntiForgeryToken()) на странице cshtml, которая генерирует файл cookieRequestVerificationToken_Lw. Значения атрибута в этом файле cookie - HTTP и Secure. Но мне нужно также установить SameSite. Как мне этого добиться?
@Html.AntiForgeryToken()
__RequestVerificationToken_Lw__
0 ответов
Это может помочь?
в Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_PreSendRequestHeaders(object sender,EventArgs e) {
// This code will mark the __RequestVerificationToken cookie SameSite=Strict
if (Request.Cookies.Count>0) {
foreach (string s in Request.Cookies.AllKeys) {
if (s.ToLower() == "__requestverificationtoken") {
HttpCookie c = Request.Cookies[s];
c.SameSite = System.Web.SameSiteMode.Strict;
Response.Cookies.Set(c);
}
}
}
}
}