79323668

Date: 2025-01-02 12:19:53
Score: 1
Natty:
Report link

1. Disable Browser Caching for Protected Pages Prevent the browser from caching sensitive pages such as the user profile page. Use the appropriate HTTP headers to instruct the browser not to cache the page.

Add the following headers to your protected pages in your .NET 8 MVC application:

Response.Headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"; Response.Headers["Pragma"] = "no-cache"; Response.Headers["Expires"] = "-1";

Alternatively, create a reusable filter or middleware to apply these headers globally to protected pages: public class NoCacheFilter : ActionFilterAttribute { public override void OnResultExecuting(ResultExecutingContext context) { context.HttpContext.Response.Headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"; context.HttpContext.Response.Headers["Pragma"] = "no-cache"; context.HttpContext.Response.Headers["Expires"] = "-1"; base.OnResultExecuting(context); } }

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Lakhveer Singh ATR846