-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.

DOTNET Dev
  • 77
  • 12

3 Answers3

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
  • 593
  • 2
  • 12
0

Thanks For The Answers but Finally best solution for This question for me.

In _Layout.cshtml, Add a version Where We Linked The Path of Angular and Css files. Browser will detect this is a new File and Then replace it. Now clear History/cache is not needed. Code: ?v=1

example:

<script src="~/Scripts/angularcontroller.js?v=1"></script>

<script src="~/Css/style.css?v=1"></script>
DOTNET Dev
  • 77
  • 12