GZIP in .net core not working

后端 未结 7 991
不思量自难忘°
不思量自难忘° 2021-02-03 22:38

I\'m attempting to add Gzip middleware to my ASP.net core app.

I have added the following package :

\"Microsoft.AspNetCore.ResponseCompression\"

7条回答
  •  天涯浪人
    2021-02-03 22:45

    Solved it by putting

    app.UseResponseCompression();

    before

    app.UseMvc();

    in Startup.Configure, i.e:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
    
            app.UseResponseCompression(); // <--
            app.UseHttpsRedirection();
            app.UseMvc(); // <--
        }
    

提交回复
热议问题