相关疑难解决方法(0)

响应缓存在 asp.net 核心项目中不起作用

我尝试在 asp.net core 项目中实现响应缓存,但它不起作用。这是 startup.cs

             public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCaching();
        services.AddMvc();
    }




      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
         app.UseResponseCaching();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
Run Code Online (Sandbox Code Playgroud)

这是我的控制器。

    [ResponseCache(Duration = 30)]
public IActionResult Index()
    {
        ViewBag.IsMobile = RequestExtensions.IsMobileBrowser(ContextAccessor.HttpContext.Request);

        return View();
    }
Run Code Online (Sandbox Code Playgroud)

但仍然缓存控制标头 id

              cache-control ?no-cache, no-store
Run Code Online (Sandbox Code Playgroud)

我缺少的地方请帮助。此响应缓存不起作用,我从 Microsoft 文档中获取指导

asp.net-mvc caching asp.net-core

7
推荐指数
1
解决办法
4817
查看次数

ResponseCache 在网络核心 3.1 中不起作用

我尝试了解 .NET Core 3.1 中的响应缓存。但它并没有如我所愿。我在 Chrome devtool 中查看了网络,它显示了带有cache-control: no-cache, no-store.

\n

我还发现 Response headerHeaderCacheControl{public,max-age=100}在 Actionfilter 中。这是我期望的值,但浏览器中的实际响应标头是no-cache.

\n

Startup类\xef\xbc\x9a

\n
public void ConfigureServices(IServiceCollection services)\n{\n    services.AddResponseCaching(options=> \n    {\n        options.SizeLimit = 1024;\n        options.MaximumBodySize = 1024 * 1024 * 100;\n        options.UseCaseSensitivePaths = false;\n    });\n}\n\npublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)\n{   \n    if (env.IsDevelopment())\n    {\n        app.UseDeveloperExceptionPage();\n    }\n    app.UseCookiePolicy();\n    app.UseStaticFiles();\n    app.UseRouting();\n    app.UseAuthentication();\n    app.UseAuthorization();\n    app.UseResponseCaching();\n    app.UseEndpoints(endpoints =>\n    {\n        endpoints.MapControllerRoute(\n            name: "default", \n            pattern: "{controller=Home}/{action=Index}/{id?}");\n    });\n}\n
Run Code Online (Sandbox Code Playgroud)\n

控制器:

\n
[ResponseCache(Duration = 100, …
Run Code Online (Sandbox Code Playgroud)

.net c# browser caching .net-core

3
推荐指数
1
解决办法
3882
查看次数

标签 统计

caching ×2

.net ×1

.net-core ×1

asp.net-core ×1

asp.net-mvc ×1

browser ×1

c# ×1