【发布时间】:2017-06-25 11:22:08
【问题描述】:
我的 ASP.Net Core MVC 应用程序添加了 Antiforgery 中间件,如下所示:
startup.cs
services.AddMvc();
services.AddSession();
services.AddCaching();
services.AddSession(o =>
{
o.IdleTimeout = TimeSpan.FromMinutes(120);
});
services.AddAntiforgery();
我已经在视图和控制器下面添加了
查看:
<form action="/Home/Login" method="post" id="staff-login" autocomplete="off">
@Html.AntiForgeryToken()
...
控制器
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Login(IFormCollection formCollection)
{...}
问题是当用户遇到不同的表单时,用户总是低于。
System.InvalidOperationException: 无法使用防伪令牌 解密。 ---> System.Security.Cryptography.CryptographicException: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 在 钥匙圈。
我找到了一个解决方案,建议在 web.config 中设置一对静态验证/解密密钥,但似乎该解决方案仅适用于经典的 asp.net 应用程序。在 ASP.Net core 中应该怎么做?
【问题讨论】:
-
查看这个解释:docs.microsoft.com/en-us/aspnet/core/security/data-protection/…。您可能需要在那里重用相同的键值(通过将键持久化到特定目录路径)。
标签: c# asp.net asp.net-mvc antiforgerytoken