-2

My question is ,
Can i clean Browser cache/history through code(c#).
because, Browser always stored previous angular/css. Everytime, we have to clear manually(By Cntrl+Shift+Del).
Is there any C# Code to clear history with button click.
Thank you.

Developer
  • 89
  • 1
  • 14

2 Answers2

0

Can try like this:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
Dashrath
  • 11
  • 2
0

Your issue is about the css and js files are cached in the browser.

Please look at the default template of Asp Mvc Application.

_Layout.cshtml should have this at the bottom

@Scripts.Render("~/bundles/jquery")

In BundleConfig.cs, you need to add this at the bottom of the RegisterBundles method

BundleTable.EnableOptimizations = true;

You should see the source of the web page the scripts have some extra version

<script src="/bundles/jquery?v=2u0aRenDpYxArEyILB59ETSCA2cfQkSMlxb6jbMBqf81"></script>

In this way, whenever you have changes in your js or css files, version will change so browser will treat this as another file instead of the previous cached version of js or css files.

In Asp.Net Core MVC, it is much easy using asp-append-version

<script src="~/js/site.js" asp-append-version="true"></script>
rjs123431
  • 688
  • 4
  • 14