C# - Prevent Scripts From Being Cached Programmatically?
Feb 21, 2011
I would like to ask if there is a way to prevent Firefox from caching scripts (.js files).
I have a project (ASP.Net Web App) with caching issue on firefox. When I first run the application (script is being cached on firefox) and modify the script and rerun the application, firefox is using the cached script instead of the updated one.
I'm using Firefox 3.6.13.
I already tried using HttpHeaders but it seems like firefox is ignoring my codes.
Here is my code:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
HttpContext.Current.Response.Cache.SetNoStore();
I tried placing this code at global.asax > Application_BeginRequest and at MasterPage.aspx.cs > Page_Load, but it isn't working.
View 3 Replies
Similar Messages:
Nov 9, 2010
Is there a way to prevent a page from being cached based on some logic?
I want to cache anonymous access to a page, so I can set VaryByCustom="user" and have some magic in Global.asax's GetVaryByCustomString method. Ok. But I don't actually want to cache the page if the user's authenticated, only if it's not authenticated. Is there a way to specify this kind of thing?
The reason I want the data to not be added to the cache to begin with (instead of added with some random key) is that as the cache grows things get thrown out and I don't want the non-authenticated version to get thrown out.
View 2 Replies
Apr 26, 2010
I have an input field on a webpage that contains a credit-card number. What is the best way of preventing the browser from caching this value?
Any solution needs to work on a large selection of browsers.
View 2 Replies
Aug 23, 2010
In my ASP.NET app, I noticed that the results of any web service calls are cached. I don't want any results to be cached, how can I stop the browser from caching the results?Update:Here's the proxy code generated by calling the web service URL appending '/js', e.g. /mywebservice.asmx/js
var MyWebService=function() {
MyWebService.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
[code]...
View 4 Replies
Feb 11, 2010
I have a GridView inside an UpdatePanel and because of some bug I can't seem to find, when I download a file (through an iframe inside another updatepanel) the background images of my buttons don't show up.I thought that, since the download doesn't really need to update the panel (which is causing the bug) I want to prevent the UpdatePanel only in this case from updating.I know that I can use the atribute "ChildrenAsTriggers = false" but I don't want to put an updatePanel1.Update() in every function called from inside the gridview.
View 1 Replies
Dec 15, 2010
i am using windows server 2003 and 2008 am about to install a web application on a server that is connected to other computers using simple wired network i.e. no active directory, no domain controller etc..
my question is:
is there a way to prevent mac addresses outside my specified list from accessing my application ? should it be through IIS or Web.config or should i put certain code in the page load events.another concern: if i use an SSL to secure my application, is it enough along with a reputable anti virus to prevent a virus to access my server through any network computer using my web application
View 3 Replies
Nov 29, 2010
why all the resources in my page are being requested EVERY single time. E.g. my site.css returns the following headers (using fiddler):
HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Mon, 29 Nov 2010 17:36:21 GMT
X-AspNet-Version: 2.0.50727
Content-Length: 9093
Cache-Control: public, max-age=2592000
Expires: Wed, 29 Dec 2010 17:36:21 GMT
Last-Modified: Mon, 08 Nov 2010 17:20:16 GMT
Content-Type: text/css
Connection: Close
But every time I hit refresh I see all the resources (css,js,images) getting re-requested. I have control over the headers returned for any and all of these resources, but I haven't figured it out yet.I have even debugged my ASP.NET app and the HttpModule is definitely being asked for the resources again.
EDIT:Ok, I removed must-revalidate, proxy-revalidate from the headers and that is getting me closer to where I want to be, now when I press back it still requests my css/js files when I press back.
View 2 Replies
Mar 29, 2011
I would like to cache a collection in the viewstate, but I wonder if there is a better way to add an item to this collection!
private List<MyClass> CachedItems
{
get { return (List<MyClass>)ViewState["CachedItems"]; }
set { ViewState["CachedItems"] = value; }
}
private void AddToCachedItems(MyClass item)
{
CachedItems = CachedItems.Concat(new[] { item }).ToList();
}
View 1 Replies
Apr 20, 2010
Is it possible to detect whether an ASP.NET Page is about to be cached and if so, how?The HttpCachePolicy object provides only set-methods. The VaryByParams name-value collection is useless if values other than "None" and "*" are set as it impossible to enumerate them and you can only access them by key
View 1 Replies
Jan 14, 2010
I am developing a website in ASP.NET and I am using various javascript frameworks/libraries. The different files belonging to these frameworks/libraries rarely changes thus there is no reason to refresh those files once they have been sent to the client browser (atleast not everytime a page is served).I see that the HttpContext object can be used somehow, that I can set the content expiration on the files/folders on the IIS, or maybe setup somekind of caching in the web.config file. 1. What is best practice/what approach should I take
View 2 Replies
Oct 22, 2010
Not really sure how to do this but i can cache the dictionary like this:
Cache.Insert("CacheName", Dictionary)
need some direction. the dictionary is two string values taken from a database. The user will input a string and i need to compare it against the values in the cached dictionary.
View 2 Replies
May 8, 2010
I'm having an issue when using the Asp.Net Cache functionality. I add an object to the Cache then at another time I get that object from the Cache, modify one of it's properties then save the changes to the database.
But, the next time I get the object from Cache it contains the changed values. So, when I modify the object it modifies the version which is contained in cache even though I haven't updated it in the Cache specifically. Does anyone know how I can get an object from the Cache which doesn't reference the cached version?i.e.
Step 1:
Item item = new Item();
item.Title = "Test";
Cache.Insert("Test", item, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
Step 2:
Item item = (Item)Cache.Get("test");
item.Title = "Test 1";
Step 3:
Item item = (Item)Cache.Get("test");
if(item.Title == "Test 1"){
Response.Write("Object has been changed in the Cache.");
}
I realise that with the above example it would make sense that any changes to the item get reflected in cache but my situation is a bit more complicated and I definitely don't want this to happen.
View 2 Replies
Dec 17, 2010
I read few xml files from a location and cache them using Http context cache. Anytime the xml files changes i have to do a IISReset to view the latest changes.
I use this
System.Web.HttpContext.Current.Cache
I have to use the caching as i don't want to read all the xml files all the time. i read it once and caches them for a day. They get reset whenever apppool recyles or anyone manualy do a IISReset.
Is there anyway in asp.net to invalidate the cache if someones changes the xml file.
View 1 Replies
May 3, 2010
My web page is still displaying a previously cached versions of the page. I have this in the page_load event:
Response.Clear();
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1;
Response.CacheControl = "no-cache";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
I have this in the Page_Init:
protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}
View 2 Replies
Apr 19, 2010
There are certain tables that get called often but updated rarely. One of these tables is Departments. So to save DB trips, I think it is ok to cache this table taking into consideration that the table has very small size. However, once you cached it an issue of keeping the table data fresh occurs. So what is the best way to determine that the table is dirty and therefore requires a reload and how that code should be invoked. I look for solution that will be scalable. So updating the cache on single right after inserting will not resolve the issue. If one machine inserted the record all other on the farm should get notified to reload the cache.
View 3 Replies
Dec 23, 2010
The Stylesheet in the App_Theme folder gets cached in the browser. What should be the approach? so that whenever there is a new deployment the browser should take the latest stylesheets and not the one cached in the browser.
This was happening for other css(which are not in theme folder) too, so used custom control as mentioned in the link
[URL]
How this could be done for the CSS in the Theme folder?
Edit: The theme name is mentioned in the web.config as mentioned below. so its not just the html link tag which I had solved by using the method mentioned in the link.
<pages styleSheetTheme="Default">
<controls>
</controls>
</pages>
View 3 Replies
Mar 6, 2010
Lets say you have a page with headers that tell the browser not to cache.Also, this page has already been posted back to itself.Now you hit the refresh button and you click cancel on the IE modal box with the "previously submitted..." message.You get "Webpage has expired". This doesn't happen in FF or Chrome.Is there a way to prevent the "Webpage has expired" message in IE?Since the page isn't cached, I guess IE has nothing to render.But if the page isn't cached and FF and Chrome shows it, I guess they just show the page as previously shown?
View 1 Replies
Jul 16, 2010
I am using the SqlSiteMapProvider to build my Sitemap ... but I'm guessing that this question is valid for any type of site map.
There's a very specific instance where I need to rebuild the sitemap because the user completes a task and I need the Sitemap to rebuild to reflect that. I don't want to get rid of the natural caching that comes with the Sitemap stuff so I'm wondering if there's some way I can clear the cached map just when this certain task gets completed.
Is there some [Sitemap].clear() type method I can run for this?
View 1 Replies
Jul 16, 2010
"Firstly check if "default.aspx" page is cached on the browser or not; if yes then Response.Redirect("default1.aspx"); else Response.Redirect("default2.aspx")
View 5 Replies
Mar 16, 2011
I have several JS proxies generated on the page through using code like:
scriptManager.Services.Add(new ServiceReference("~/Service.asmx"));
This code generates the following JS proxy on ASPX page where it is used:
<script src="../../Service.asmx/js" type="text/javascript"></script>
This file is not being cached in browser cache. I checked in firebug and in header it says:
Cache control: private
All other JS and CSS files are being cached with "Cache-Control: public,max-age=8640000". In web.config I have:
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="100.00:00:00" />
</staticContent>
How can I get JS Proxy files to cache?
View 1 Replies
May 21, 2010
I am running into an odd problem, and this is the only thing I can think of. I'm storing a list in cache, and I am randomly losing items from my list as users use the site. I have a class that is called that either goes to cache and returns the list from there, or if the cache is over a certain time frame old, it goes to the database and refreshes the cache. So when I pull the data from cache, this is what it looks like....
results = (List<Software>)cache["software"];
And then I return results and do some processing, filter for security, and eventually it winds up on the screen. For each Software record, there can be multiple resources attached to it, and based on how the security goes they may see some, all, or none of the records. So in the security check it will remove some of those resources from the software record.So my question is.... when I return my results list, is it a reference directly to the cache object? So when I remove a resource from the software object, it is really removing from cache as well? If that is the case, is there any way to not return it as a reference?
edit: I think I may have just answered my own question.... so if I do something like this:
results = new List<Software>((List<Software>)cache["software"]);
it will copy the cached list to my results list, correct?
View 1 Replies
Jan 20, 2011
How do I remove all of the pages I have placed in the output cache? I know you can use
HttpResponse.RemoveOutputCacheItem to remove a single page but how do I "clear" it, i.e. removing ALL pages?
View 5 Replies
Jan 11, 2011
I have a page that searches and displays records. Users enter a record number and then select the type of record to display from a dropdownlist control. They then edit some data on the page, and the app does some calculations based on the type of record that is selected from the drop down. How do i get to successfully pass the value from the dropdownlist to the method that does the calculation to ensure that the right formula is used? Here is the code that I currently have.
[Code]....
then the code behind to do the calculation looks like this...
[Code]....
After stepping through the code, i noticed that when it gets to the "foreach" block, the value selected by the ddlRecordType dropdownlist is always the default which is "select one" and not any of the other selections that might have been selected.How do I get this to work, so that it can maintain the value selected from the dropdown and used in the code behind?
[Code]....
View 3 Replies
Mar 7, 2010
I have an ASP.NET project which is a front-end to a database. In addition to the large tables, the DB contains a few small tables to normalize the larger tables with common values. I have a VB.NET project which loads the smaller tables into memory, using "Shared" (i.e., "static" in C#) member variables, and uses them. I have a call to load the tables in Global.asax - Application_Start. This works for a while. That is, Application_Start runs when I first run my project, loads the cached values, and will correctly keep them in memory for a while.
What I'm seeing (when running my project via Visual Studio 2008 Debugger, hosted locally) is:
A) The Application_Start code will run more than once. Not in a row, but after the user has navigated to some other pages, I'll see (my breakpoint in) another call to initialize the cache, coming form Application_Start. Is it expected?
B) The "Shared" variable that was set to True when the cache was initialized is now False again (which should only happen when the class is first loaded). Similarly, all the data that was chached is no longer present. That is, it looks like VB is unloading all the Shared members. Is this expected?
If these are the expected behaviors, is there a way to do what I want? The code is in a module that is also used by other (non-ASP.NET) projects, and seems to work correctly for them. I'd rather not have to duplicate this functionality for something specific to ASP.NET, but would like to know what my options are.
View 1 Replies
Jun 6, 2010
In an ASP.NET 3.5 VB web app, I successfully manage to cache an object containing several personal details such as name, address, etc. One of the items is CreditNum which I'd like to change in the cache on the fly. Is there a way to access this directly in the cache or do I have to destroy and rebuild the whole object just to change the value of objMemberDetails.CreditNum?The cache is set using:
Public Shared Sub CacheSet(ByVal key As String, ByVal value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(key & "_" & userID) = value
End Sub
View 1 Replies