我尝试实施响应缓存并禁用某些操作的默认防伪行为,但是我得到的每一个请求都是"
警告:Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery [8] '缓存控制'和' Pragma'标题已被覆盖并设置 到没有缓存,没有商店'和“没有缓存”#39;分别防止缓存 这个回应。任何使用防伪的反应都不应该 缓存。
我在动作上定义了 IgnoreAntiforgeryToken 。还有另一种关闭默认防伪的方法吗?
Startup.cs :
public void ConfigureServices(IServiceCollection services)
{
.
.
.
services.AddResponseCaching();
services.AddMvc(options =>
{
options.CacheProfiles.Add("Default",
new CacheProfile()
{
Duration = 240
});
options.CacheProfiles.Add("NoCache",
new CacheProfile()
{
Location = ResponseCacheLocation.None,
NoStore = true
});
})
.AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
.
.
.
app.UseResponseCaching();
}
Controller.cs :
[IgnoreAntiforgeryToken]
[ResponseCache(CacheProfileName = "Default", VaryByQueryKeys = new string[] { "id" })]
[HttpGet("/Shop/Category/{id:int}", Name = "Category")]
public IActionResult Category(int id)
{
var result = this.AppHelper.ModelHelper.GetCategoryWrap(id);
return View(result);
}