From 88e05f71a5bd7a6b2330d5fd945bbe0d15677e1a Mon Sep 17 00:00:00 2001 From: Jass Bagga Date: Thu, 7 Dec 2017 12:11:44 -0800 Subject: [PATCH] Add no-cache header to error pages (#182) Addresses #123 --- .../content/Aurelia-CSharp/Controllers/HomeController.cs | 1 + .../content/Knockout-CSharp/Controllers/HomeController.cs | 1 + .../content/Vue-CSharp/Controllers/HomeController.cs | 1 + .../content/RazorPagesWeb-CSharp/Pages/Error.cshtml.cs | 2 ++ .../content/StarterWeb-CSharp/Controllers/HomeController.cs | 1 + 5 files changed, 6 insertions(+) diff --git a/src/Microsoft.AspNetCore.SpaTemplates/content/Aurelia-CSharp/Controllers/HomeController.cs b/src/Microsoft.AspNetCore.SpaTemplates/content/Aurelia-CSharp/Controllers/HomeController.cs index 1834659896..e16d8b7b37 100644 --- a/src/Microsoft.AspNetCore.SpaTemplates/content/Aurelia-CSharp/Controllers/HomeController.cs +++ b/src/Microsoft.AspNetCore.SpaTemplates/content/Aurelia-CSharp/Controllers/HomeController.cs @@ -14,6 +14,7 @@ namespace AureliaSpa.Controllers return View(); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier; diff --git a/src/Microsoft.AspNetCore.SpaTemplates/content/Knockout-CSharp/Controllers/HomeController.cs b/src/Microsoft.AspNetCore.SpaTemplates/content/Knockout-CSharp/Controllers/HomeController.cs index e952e8d35d..593ae37d35 100644 --- a/src/Microsoft.AspNetCore.SpaTemplates/content/Knockout-CSharp/Controllers/HomeController.cs +++ b/src/Microsoft.AspNetCore.SpaTemplates/content/Knockout-CSharp/Controllers/HomeController.cs @@ -14,6 +14,7 @@ namespace KnockoutSpa.Controllers return View(); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier; diff --git a/src/Microsoft.AspNetCore.SpaTemplates/content/Vue-CSharp/Controllers/HomeController.cs b/src/Microsoft.AspNetCore.SpaTemplates/content/Vue-CSharp/Controllers/HomeController.cs index 70ebae7388..2850fc2dfa 100644 --- a/src/Microsoft.AspNetCore.SpaTemplates/content/Vue-CSharp/Controllers/HomeController.cs +++ b/src/Microsoft.AspNetCore.SpaTemplates/content/Vue-CSharp/Controllers/HomeController.cs @@ -14,6 +14,7 @@ namespace VueSpa.Controllers return View(); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier; diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Error.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Error.cshtml.cs index 7c5b9e4736..d3ef08b414 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Error.cshtml.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Error.cshtml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace Company.WebApplication1.Pages @@ -13,6 +14,7 @@ namespace Company.WebApplication1.Pages public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public void OnGet() { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/HomeController.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/HomeController.cs index 50363a31ea..f04cdbaa55 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/HomeController.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/HomeController.cs @@ -38,6 +38,7 @@ namespace Company.WebApplication1.Controllers #if (OrganizationalAuth) [AllowAnonymous] #endif + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });