【问题标题】:ASP.net Core ResponseCache and RedirectToAction. How can anonymous only responses be cached?ASP.net Core ResponseCache 和 RedirectToAction。如何缓存仅匿名响应?
【发布时间】:2017-08-16 02:07:30
【问题描述】:

给定以下控制器:

public class MyController : Controller
{
    [AllowAnonymous]
    [ResponseCache(VaryByQueryKeys = new string[] { "id" }]
    public async IActionResult Action1(string id)
    {
        if (User.Identity.IsAuthenticated)
           return RedirectToAction("Action2", new {id = id});

        return View();
    }


    [Authorize]
    public async IActionResult Action2(string id)
    {
        return View();
    }
}

假设经过身份验证的用户导航到“/Mycontroller/Action1/20”。响应会被缓存吗?

如果答案是肯定的,如何只缓存匿名响应?

【问题讨论】:

    标签: caching asp.net-core redirecttoaction responsecache


    【解决方案1】:

    在您在此处显示的代码中,答案是否定的。 RedirectToAction 将向您的站点发出单独的请求(301 重定向),该请求将完全独立于第一个请求(对 Action1)进行处理。

    值得考虑响应缓存对非匿名用户的影响,但在这种情况下,您的方案将不会受到这些潜在影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 2018-02-08
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2018-06-05
      相关资源
      最近更新 更多