0
所以我按照指南here(不包括Application Insights等一些特定於應用程序的項目)。ASP.NET Core 1.1中的瀏覽器緩存沒有觸發
Startup.cs修改在這兩個方面:
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression(options =>
{
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "image/svg+xml" });
});
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection")));
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddResponseCaching();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseResponseCompression();
app.UseResponseCaching();
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
// Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
和各種控制器的網頁,我打電話ResponseCache中像這樣(將其設置爲2分鐘,不知道這是什麼人traditionallly設置到):
[ResponseCache(Duration = 120)]
public IActionResult Index()
{
return View();
}
在部署到Azure之後,我可以重複擊中F5並仍然可以看到200個網絡流量。目標是緩存CSS,JS和頁面(以及不屬於[Authorize]管理控制器的頁面)。
更新(各種):不幸的是,我已經審查了很多指南,似乎他們都固有地說同樣的事情(主要區別是不依賴於響應緩存Nuget包,並與一個硬編碼版本,雖然相同的非結果),但由於某種原因,這是行不通的。在Web Forms應用程序(2.0升級到4.0)中,我能夠以最小的努力實現這一目標。
通常,當我只碰到F5時,我在那裏獲得304s以及其他已完成的網站。這一個是所有的200。現在,我可以做一個很難繞過緩存的地方,但這不是這種情況。使我注意到這一點的主要症狀是PageSpeed Insights標記圖像/ css /等。因爲沒有緩存標題 – Robert
要進行測試,請將A元素添加到正在緩存的頁面(或操作),然後嘗試導航到該頁面(或操作)。你會注意到這個動作沒有被擊中。 –
從索引開始,我點擊了開發工具中Network標籤的頁面內的鏈接。所有的資產都回來了200個。即使是構成主題的佈局和CSS的一部分的圖像(也可以從佈局中獲得)。 – Robert