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.
Asked
Active
Viewed 1,271 times
-2

Developer
- 89
- 1
- 14
-
4You need to fix the problem, not automate cache clearing. – DavidG Dec 03 '19 at 13:18
-
1[You want to investigate what is called cache busting](https://css-tricks.com/strategies-for-cache-busting-css/) – Crowcoder Dec 03 '19 at 13:19
-
@DavidG, you mean ,there is no way through coding.. – Developer Dec 03 '19 at 13:21
-
are you using asp.net core? – rjs123431 Dec 03 '19 at 13:21
-
@rjs123431 only .net – Developer Dec 03 '19 at 13:23
-
No, I mean use cache busting e.g. https://stackoverflow.com/questions/39647810/how-to-prevent-browser-cache-on-angular-2-site – DavidG Dec 03 '19 at 13:24
-
you mention about C#, angular/css, it means this is a web application .net framework, it that correct? – rjs123431 Dec 03 '19 at 13:24
-
yes @rjs123431. – Developer Dec 03 '19 at 13:25
-
1okay, so you don't need to clear the cache, possible solution in .net mvc is to append a version of the js and css files – rjs123431 Dec 03 '19 at 13:31
2 Answers
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