I'm trying to figure out how the easiest way would be to force endusers browser to clear cache.
We are working in visual studio with .Net WebForms and AngularJs
So every time we deploy our .Net project to test or production enviroment we got problems with cache saving old javascript and hides new implementation...
I know a couple solutions but I wanna see if there are any other?
Thanks in advance!
Right click in this page and select view source, you will see static files suffixed as follows:
<script src="//cdn.sstatic.net/Js/stub.en.js?v=b1fcfe635df7"></script>
Basically this is kind of the best method, generate some suffix and append that to the end of all of your static files as a querystring parameter. That will force the browser into thinking that the file is new, i.e. if the querystring has changed...
The rub here though is how often do you change those files... how often do you want to force the user to download new static files... using a generated timestamp could force the user to download the file everytime they visit the site, often not ideal.... Maybe use the web.config date or something like it.
you can add below settings in web.config to disable caching
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
Related
I'm using the following code these days to include my JS and CSS files within my (Umbraco) websites:
#using ClientDependency.Core.Mvc;
#{
Html.RequiresCss("link-to-file", 1);
Html.RequiresCss("link-to-file", 2);
Html.RequiresJs("link-to-file", 1);
}
I've noticed that the following files is being called when loading the site:
https://mysite.nl/DependencyHandler.axd?s=L2xpYi9zY3JpcHRzL21vZGVybml6ci5jdXN0b20uanM7L2xpYi9zY3JpcHRzL2pxdWVyeS5kbG1lbnUuanM7L2xpYi9zY3JpcHRzL3NpdGUuanM7&t=Javascript&cdv=1511701721
After making changes to either the CSS or JS files and uploading them to the server, the DependencyHandler call remains the same. Therefor, the CSS and JS are being cached on the server and I don't see my changes on the live site.
I need to manualy change the ClientDependency version (within ClientDepenedency.config). If I change that, the 'cdv' value at the end of the DependencyHandler call is changed (to the version I changed it in ofcourse), and the new files are being served.
Is there a way to get the DependencyHandler notice changes in the files and automaticly refresh the cache?
If anyone is still ask this question, as a response, you can enter
Shift+F5
on search engine.
Maybe, it is a response this question.
By the way if you were doing <compilation defaultLanguage="c#" debug="true" ...> in Web.config, you can look js or css files.
If this problem isn't cache problem, should been controled server connection, services,.. Except that, if it is a OOP's problem, wouldn't umbraco throw a mistake? As I said, I understood this text as a cache problem and I response as it.
Hope it work.
Following this answer, I've enabled serving JavaScript and CSS from my Views folder which is helping my project's organization. Unfortunately, while I'm developing, I find I have to disable my browser cache in order to see my changes. I'd like to be able to develop without keeping DevTools open just to disable the cache.
I figure my issue is the System.Web.StaticFileHandler serving up the files in such a way that the browser caches them. I've tried using System.Web.Handlers.TransferRequestHandler like this answer suggests, but then I get 500 Server Errors instead.
Is my understanding of the problem correct? How can I resolve my issue?
Note: Not that it's relevant, but I intend to add a config transform to switch back to the static handler for releases.
Using ASP.NET 4.0, IIS 7.5.
I have a website engine, I have just implemented a way for this to tell if it's being loaded on mobile and instead of loading Controls\MyControl.ascx it loads Mobile\Controls\MyControl.ascx. This works well for my controls and also my MasterPage.Master file.
What I can't figure out however is how I can do the same with Default.aspx. This needs to be done on the fly programatically as I need to be able to check if it's mobile version. I was thinking of doing something on a pre-init event in globals but not sure if that's the best way.
Note: I don't want to use inline code on Default.aspx and just display different content base on my Mobile flag as my scenario goes one step further by basing the file on customer as well and this would mean having one huge Default.aspx for all customers which wouldn't be manageable.
Changing the default document on the fly is not possible in any practical sense.
Writing to the web.config on the fly to load a mobile version of a default page is quite frankly terrible and not an answer to the true context of your issue. I would feel irresponsible as a developer if I even proposed this as an answer to loading a mobile version of a default page.
I was trying to help you solve your problem and not just answer the base question in the title. As we all know, changing the web.config will restart your application and would not serve as a true solution, as you could not do this and achieve any kind of performance.
Here is the BEST alternative (IMHO) to dealing with mobile browsers.
http://51degrees.codeplex.com/
HTH!
For anyone else looking at this I have found a solution but I am not sure I will implement it as I don't like the idea of updating the web.config file at run time. Using the Microsoft.Web.Administration namespace you can update the server.webServer -> defaultDocument section programmatically. Doing this allows you to change the path to default.aspx and it will load based on the variables you set.
This link should provide more information: http://blogs.msdn.com/b/saurabh_singh/archive/2007/11/24/accessing-iis-7-0-features-programmatically-from-configuration-file-s-c.aspx
Also, the Microsoft.Web.Administration dll isn't available directly in VS so you need to add it from %windir%\syswow64\inetsrv (64bit version).
I have used FCKeditor in my project. It worked fine before i add url rewriting in my project.
Now i can not upload images from my fckeditor properly.
I am using Intelligencia.UrlRewriter for url rewriting in asp.net.
Can any one help me to get out of this kind of problem?
I'm guessing that the ISAPI rewrite rules are affecting where FCKEditor accesses the necessary html files causing a permanent 404.
Add a rule to exclude the images folder from being rewritten and you should be good to go.
Take a look here for some information about setting rules: http://urlrewriter.net/index.php/support/using
Do you have web.config file? If yes, try these settings in that file
<appsettings>
<add key="FCKeditor:UserFilesPath" value="~/UserFilesUpload" />
</appsettings>
This is a bit tricky and I'd be glad if you guys could give me some pointers on this one. Here is what I want to do:
A user tries to access
myapp.com/data/123456.mp3
test.mp3 doesn't exist
The system sends the user to
myapp.com/data/error.apsx?file=123456.mp3
I need this in order to handle the way a large system is supposed to serve mp3 files.
If a user tries to access myapp.com/otherFolder/notHere.whatever, the system returns the standard 404 error normally.
I know there are ways to specify that in IIS, but I'd love it if there was something I could do programmatically or just withing my .net project.
edit:
I've created a web.config file in myapp.com/data/
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="/data/mp3/full/serveMp3.aspx"/>
</system.web>
</configuration>
This doesn't seem to be working.
Custom Errors
http://aspnetresources.com/articles/CustomErrorPages.aspx
In your web.config.
<customErrors
mode="RemoteOnly"
defaultRedirect="~/errors/GeneralError.aspx"
/>
The first thing you have to do is make sure ASP.NET gets to handle these file requests since by default .mp3 isn't an ASP.NET extension and this will just be handled by IIS.
Couple of ways to actually do this once you are handling it spring to mind.
The first is to create an HttpModule which watches the OnUnhandledException event. Since ASP.NET throws 404's (and all HTTP errors) as HttpException type exceptions the module will provide you with a place to catch, parse the request, and redirect to your own ends.
The other means is to create a web.config at the folder level you care about (these can be nested remember) and create customerror section there. This is more straightforward but affords much less control. All things considered I would favour the module generally.
probably you could put a web.config indide the folder that you want to put a specific error and put in that webconfig the customerror tag with the page indicated
or you can use the location tag inside the main web.config
but i'm not sure about this