#asp.net-mvc #google-chrome #cookies #iframe #samesite
#asp.net-mvc #google-chrome #файлы cookie #iframe #samesite
Вопрос:
Мне трудно изменить атрибут SameSite в ASP.NET Приложение MVC. Вот сценарий: я пытаюсь загрузить свой ASP.NET приложение внутри iframe и из-за изменений в Google Chrome 80 мне нужно установить атрибут SameSite для файлов cookie, чтобы иметь возможность использовать файл cookie аутентификации в iframe. Я перешел по этой ссылке SameSite Cookie
и применил изменения, но по какой-то причине это не изменяет атрибут SameSite для файлов cookie FedAuth и FedAuth. Вот код для создания файла cookie сеанса:
SessionAuthenticationModule session = FederatedAuthentication.SessionAuthenticationModule;
SessionSecurityToken sToken = session.CreateSessionSecurityToken(principal, null, DateTime.UtcNow, DateTime.UtcNow.AddHours(24), isPersistant);
session.AuthenticateSessionSecurityToken(sToken, true);
session.WriteSessionTokenToCookie(sToken);
web.config
<httpRuntime requestValidationMode="2.0" maxRequestLength="28672" targetFramework="4.7.2" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<compilation debug="true" targetFramework="4.7.2">
<httpCookies httpOnlyCookies="true" sameSite="None" requireSSL="true"/>
<authentication mode="Forms">
<forms requireSSL="true" cookieSameSite="None"/>
</authentication>
<sessionState cookieSameSite="None" />
<system.identityModel.services>
<federationConfiguration>
<cookieHandler mode="Default" requireSsl="true" persistentSessionLifetime="0.06:00:00" path="/"/>
</federationConfiguration>
У вас есть какие-либо предложения?
Ответ №1:
Я все еще новичок в работе с wsfed, но добавление этого в мой Global.asax.cs
, похоже, сработало для меня:
void WSFederationAuthenticationModule_SignedIn(object sender, EventArgs e)
{
foreach (string key in Response.Cookies.AllKeys)
{
if (key.StartsWith("FedAuth"))
{
var cookie = Response.Cookies[key];
cookie.SameSite = SameSiteMode.None;
cookie.Secure = true;
}
}
}