【发布时间】:2021-03-06 00:38:20
【问题描述】:
在我的应用中使用 SustainSys.Saml2 库时出现浏览器错误:
400 Bad Request
Request Header Or Cookie Too Large
nginx/1.14.0
我认为减少我的 cookie 大小可能会有所帮助,我只需要来自声明数据的电子邮件,所以我认为如果我可以保存电子邮件声明并删除其他声明,它可能会减少我的 cookie 大小和修复此错误。
我阅读了对类似问题 (SustainSys.Saml2 Request length header too long) 的回复,并查找了有关如何实施 AcsCommandResultCreated 以删除未使用的声明(并希望减少 cookie 大小)的一些信息。我没有找到很多文档,但确实拼凑了一些想法和代码来尝试尝试一下。
我已经在我的 global.asax 以及一个控制器操作中尝试了这段代码(我在 Saml2/Acs 之后创建了“returnUrl”)。我的 FedAuth cookie(由 Saml2/Acs 设置)看起来一点也不小。任何cmets或建议?谢谢。
// Check if email claim exists
var principal = ClaimsPrincipal.Current;
var userEmail = principal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email)?.Value;
// Create new command result that only contains the email claim
if (userEmail != null)
{
var emailClaim = principal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email);
Sustainsys.Saml2.Configuration.Options.FromConfiguration.Notifications.AcsCommandResultCreated =
(commandResult, response) =>
{
var newCommandResult = new Sustainsys.Saml2.WebSso.CommandResult();
newCommandResult.Principal.Claims.Append(emailClaim);
commandResult = newCommandResult;
};
}
更新: 事实证明,我使用的测试环境(使用 nginx)需要增加请求头缓冲区的大小。添加这些 cookie 会将大小增加到大约 9500 字节,默认情况下,nginx 的请求标头缓冲区大小低于此大小(我认为是 8000)。联系运行 nginx 的测试服务器的代码所有者,并增加它解决了我的问题,而无需减小我的 cookie 大小。
【问题讨论】:
标签: cookies model-view-controller sustainsys-saml2 .net-framework-4.8