在我部署一些似乎可用于测试的代码之前,使用 AntiForgeryToken 是否存在任何问题?部署到 Azure WebRole 时。因为它会生成一些 html 和一个 cookie,所以我担心以下...
页面由 MVC 缓存缓存。防伪 token 的 cookie 是否会在后续的页面请求中重新发布?
该页面在多个实例的 Azure Webrole 中运行。如果接收服务器不是生成页面的服务器,会有什么问题吗?
表格来自保存在数据库中的一堆html。因此,我们建议有效地进行字符串替换以找到一个简单的 token 并交换 AntiForgery token 。 (下面的代码)这似乎有效,但让我担心。
var xtoken = "<!--AntiForgeryToken-->";
if (content.Contains(xtoken))
{
var token = HttpUtility.HtmlDecode(html.AntiForgeryToken().ToHtmlString());
content = content.Replace(xtoken, token);
}
return html.Raw(content)
以上会产生什么问题吗?
请您参考如下方法:
您不能在带有 AntiForgeryToken() token 的页面上使用缓存 - see this .
The page is running in an Azure Webrole on multiple servers
如果您的意思是在多个实例上运行的 WebRole 应该不是问题,因为默认情况下 Azure 会处理 MachineKey ( see here)
但是在部署(重新部署)之后你可能会遇到问题,因为Azure will override MachineKey
