【问题标题】:Use of AntiForgeryToken and Cached pagesAntiForgeryToken 和缓存页面的使用
【发布时间】:2015-01-21 23:42:41
【问题描述】:

在我部署一些似乎在测试中工作的代码之前,在部署到 Azure WebRole 时使用 AntiForgeryToken 是否存在任何问题。因为它会生成一些 html 和 cookie,所以我很担心以下...

页面由 MVC 缓存缓存。防伪令牌的 cookie 会在页面的后续请求中重新发出吗?

该页面在多个实例上的 Azure Webrole 中运行。如果接收服务器不是生成页面的服务器,是否有任何问题?

这些表单来自保存在数据库中的一大块 html。因此,我们建议有效地进行字符串替换以找到一个简单的令牌并交换 AntiForgery 令牌。 (下面的代码)这似乎有效,但让我担心。

        var xtoken = "<!--AntiForgeryToken-->";
        if (content.Contains(xtoken))
        {
            var token = HttpUtility.HtmlDecode(html.AntiForgeryToken().ToHtmlString());
            content = content.Replace(xtoken, token);
        }

        return html.Raw(content)

以上会产生任何问题吗?

【问题讨论】:

    标签: c# asp.net-mvc-4 azure cookies


    【解决方案1】:

    您不能在带有 AntiForgeryToken() 令牌 - see this 的页面上使用缓存。

    页面在多个服务器上的 Azure Webrole 中运行

    如果您的意思是 WebRole 在多个实例上运行,这应该不是问题,因为默认情况下 Azure 会处理 MachineKey (see here)

    但是你可能刚部署(重新部署)后就有问题,因为Azure will override MachineKey

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2018-12-10
      • 1970-01-01
      • 2011-09-24
      • 2010-10-28
      • 2014-07-06
      • 2012-01-01
      • 2021-09-30
      • 2011-08-14
      相关资源
      最近更新 更多