This may be some "best practices" thing I've overlooked or don't know about, so go easy on me please.
I have an asp.net website that populates a gridview with columns from my database table. One of those columns gets processed into a link to a word document on another server. The issue is that if a user clicks on the word document to view it, and then that document is updated on the remote server, the user cannot access the changed document until their browser cache is cleared and it's forced to go out to the network to grab a fresh copy when the link is clicked.
Basically I want to somehow force the machine never to use the cached copy of the document, but always go out to the network to get the newest copy.
Bonus question: Would this be better handled somehow by storing the documents in SharePoint?
UPDATE: using Response.Cache.SetCacheability(HttpCacheability.NoCache); in my codebehind I have now resolved the issue in FireFox, but IE8 is weird. If I update the document and then left click on it, it brings up the word doc in the IE window without the changes. However, if I make changes, save them and then middle click on the document so it opens up a new tab, the document reflects the changes. I'm mostly there...
Try adding a little extra data to the link. Here's an example using js; if you're building the url server side, it should be essentially the same:
var url = "http://www.mydomain.com/mywordfile.doc?ts=" + (new Date()).getTime();
That'll force the url to have a different query url each time, which (in theory) should force the browser to re-request and re-download it.
By chance are you seeing this with IE8 specifically? We've seen it show this behavior where caching was previously not an issue.
Typically it can be cleared up with a couple steps: explicitly telling the browser not to cache via HTTP headers, and also expiring the page immediately. Google the "pragma no-cache" header, there is typically a couple of different lines you need to add to cover all browsers.
Related
I am working on an ASP.NET/MVC4 app and I fetch data continuously and my problem is related to caching.
The problem is that when I click on a particular link in my application it works fine, but sometimes it automatically redirects to the INDEX page that is the default page.
I surfed around about this problem and found that it's a problem in Mozilla that it maintains caching of every link. But sometimes some weird things happen and it automatically redirects a particular link to the INDEX page (301 Permanently REMOVED) and also stores it in the cache such that now every time I click on that link it always redirects me to the INDEX page that's been cached.
So now I have to clear the cache in my browser every time I face this problem.
How can I make it not automatically redirect to the cached INDEX page?
You should really expand on what exactly is happening at that particular link you mention because well it should not 301 redirect unless your telling it to.
Also you say I fetch data continuously. What does this mean to us? Why is this important to know? Explain if this changes the link or the data? Are you 404ing the older data or something? That could possibly explain why you 301 back to your index.
Now with the limited information we have been given by you... if you want to prevent firefox from caching your urls/redirects simply make your url have a querystring that updates which each request. Like using a timestamp.
For example: http://example.com/return-data.asp?timestamp=1350668920
Then each time you continuously fetch data update the page's link accordingly
For example: http://example.com/return-data.asp?timestamp=1350669084
my scenario is this; the user selects the list of reports they wish to print, once they select and click on the a button, i open up another page with the selected reports ready for printing. I am using a session variable to pass reports from one page to another.
first time you try it, it works fine, second time you try it, it opens the report window with the previous selected reports. I have to refresh the page to make sure it loads the latest selections.
is there a way to get the latest value from the session every time you use it? or is there a better way to solve this problem. open for suggestions...
Thanks
C# Asp.net, IE&7 /IE 8
After doing some more checking maybe if you check out COMET it might help.
The idea is that you can have code in your second page which will keep checking the server for updated values every few seconds and if it finds updated values it will refresh itself.
There are 2 very good links explaining the imlementation.
Scalable COMET Combined with ASP.NET
Scalable COMET Combined with ASP.NET - Part 2
The first link explains what COMET is and how it ties in with ASP.NET, the second link has an example using a chat room. However, I'm sure the code querying for updates will be pretty generic and can be applied to your scenario.
I have never implemented COMET yet so I'm not sure how complex it is or if it is easy to implement into your solution.
Maybe someone developing the SO application is able to resolve this issue for you. SO uses some real-time feature for the notifications on a page, i.e: You are in the middle of writing an answer and a message pops up in your client letting you know someone else has added an answer and to click "here" to refresh.
The proper fix is to set the caching directives on the HTTP response correctly, so that the cached response is not reused without validation from the server.
When you fail to specify the cache lifetime, the client has to "guess" how long the response is good for, and the browser's guess probably isn't what you want. See http://blogs.msdn.com/b/ie/archive/2010/07/14/caching-improvements-in-internet-explorer-9.aspx
It's better to use URL paramaters. So you have a view of value of the paramaters.
I am using an HttpHandler to modify some CSS (only simple colours) on the fly, based on a technique I read about on SO.
Everything works just fine expect on the page where I am giving the user the option to specify the colours they want. Ideally as soon as the user saves his new colours and the page refreshes I want the new colours to be displayed. However they only come through when I explicitly press the browser reload or F5 key.
I appreciate that something somewhere (IIS or the browser) is doing some helpful caching of my stylesheet which 999 times in 1000 is exactly what I want, however on this particular page event I want to be able to force a reload and cause the HttpHandler to fire.
Anyone understand how this works and what I can do?
Things I have tried:
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Expires = -1;
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Because I am also using ASP.NET themes adding a querystring the stylesheet link isn't really a simple option.
Thoughts anyone?
This can be solved with technique that I use on my sites to cause reloads of assets once they have changed, such as after a deploy.
Append ?value to the end of your CSS url, where value corresponds to the version, or some unique value the browser hasn't seen yet. In my case I use the file modification time, however in your case since the CSS is dynamic on almost every pageload, I suggest generating some unique value.
Since the URL is always different, the browser will always reload it and it will never get put into its cache.
I sometimes find that I need to press CTRL+REFRESH BUTTON (or simply REFRESH BUTTON) in order for pages to be updated.
I thought this may have been a problem with using AJAX Update Panel and things, but it also happens on pages where there is no AJAX partial rendering.
I have also removed if(!isPostBack), and yet still I need to refresh the page for the contents to be updated.
Is it to do with the cache?
Does anyone know of a fix for this?
I believe it only happens with IE 7 (which I am using). I tried the same feature with Chrome, and it worked as it is supposed to.
EDIT: Unfortuanetly, it is not as easy as setting to cache header to 0 or in IE retriving the latest page always on page load. I have done these and the same problem happens.
For instance, on one part of my site, you can change the profile picture. If I choose to remove the profile picture (which should then set to the default picture), it only deletes the picture (but doesnt display the default picture). The page loads again but it still references to the picture I deleted (so I get an X for the picture). I have to go onto a different page, and then back to the profile page for me to see the default picture. CTRL + REFRESH also works.
Note that this particular problem happens under all browsers (Chrome included).
If it helps, I am using Content pages which are in a master page.
Changing your browser cache settings will fix the problem locally, but to fix it for a general case, add the header "Expires: 0" to your outbound page, which will prevent browsers from caching it at all.
To do this in C#, add this code to the page load event:
Response.AddHeader("Expires", "0");
Ctrl+refresh forces you IE to reload page from server instead of using locally cached version. First, check your browser's settings: Settings - General - Browsing history. "Check for newer versions of stored pages" should be set to "Automatically". Then, check if you're adding any "expires" header to your pages.
You can also consider setting the caching policy on the response object or set the entity tag to something different every time...
http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.aspx
The user needs to click on browse button to browse his system .He then selects a text file & clicks ok.Once he clicks ok all the data in the text file should be displayed in a text area.How do I do that? I am using JavaScript & c# designing aspx pages.It would be preferable if i avoid round trip to the server.
You can't do it without a trip to the server, the only way for you to get the content of the file is by submitting it as part of a form. You can make the trip to the server happen in an iframe via XHR and then update the text area with the result from the XHR call, so it sort of seems like one wasn't involved, but you can't directly access the content of files of the user's machine, for obvious reasons.
I know you said you would prefer a round trip, but its the only way you are going to be able to accomplish what you want.
You could put the file upload in an iframe, and do the upload behind the scenes (No page refresh, gmail does this :) ) then use AJAX to download the data and insert it into the textarea.
It can't in general be done, as answers here outline.
However, it can be done in Firefox 3+ only, using the uploadfield.files array. Other browsers would have to fall back to the server round-trip.
For security reasons, JavaScript cannot access the local filesystem like that.
Javascript cannot do that without putting a severe security risk on the user. That said, the file will need to be posted to your server.
As other posters here have indicated, you're not allowed to access the local filesystem from Javascript directly. But you can set up an action on your server to take the file form POST input, and simply echo the data right back out to the response. If you hide an iframe inside your page as the form POST target, that response data can appear in the hidden iframe, and then the page won't have to reload. Then once the iframe has loaded with the text, you can use JS to pull the text out of the iframe, and put it into the text area that you're interested in.
Alternately, if you're inclined to restrict usage to Firefox users with an extension, you should be able to accomplish this without a roundtrip using a Greasemonkey user script (see www.greasespot.com) or something like it, that uses the custom Mozilla extensions.