Web Forms :: Set OutputCache Dynamicllly?
Feb 15, 2011i have CMS that dynamically add user control to page. now i wanna use OutputCache for user control and set it from server side code. how i can do that?
View 1 Repliesi have CMS that dynamically add user control to page. now i wanna use OutputCache for user control and set it from server side code. how i can do that?
View 1 Replies<%@ OutputCache Location="None" VaryByParam="None" %>
Because when am using this line in http then the attachment is opening fine but not for https.But after removing this line then https is working fine.
I Want data OutputCache in server remove
View 2 RepliesI've got a problem using outputcache together with urlrewriting. We've got an application that rewrites url (IE [URL]). Based on the URL (/about/) we figure out which content to show. Now we're trying to add outputcache to that page:
< %@ outputcache duration="600" location="Server" varybyparam="Custom" varybycustom="RawURL" %>
And in the Global.asax we override GetVaryByCustomString like below:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom == "RawUrl")
{
return context.Request.RawUrl;
}
else
{
return string.Empty;
}
}
However, when we publish the page i'd like to invalidate the cache so that the editors see the change directly. But no matter what I try, I cannot seem to invalidate the cache. If I'd like to invalidate "/about/" I would like to do this: HttpResponse.RemoveOutputCacheItem("/about/"); That doesn't work unfortunately. The only thing that seems to work is: HttpResponse.RemoveOutputCacheItem("/page.aspx");
This clears the cache for all my pages, not just "/about/". Is there any way to invalidate the cache based on the url? Or should we provide a cache key or something per page to be able to invalidate the cache programmatically?
I read many posts about outputcaching element in asp .net MVC, but i have one question.My architecture is :1 master page, 1 page (especially news information), and a few other controls like LogOnUser / Fixed status bar etc...I want to have my news cached cause there are three query to entities, but i need too the title for SEO of my master page (title is included in a contentplaceholder in master).I tried to use renderaction outputcache but it is not possible to retrieve the title from the renderaction. Have you any idea about this problem ?Maybe it's preferable to use a general outputcache and use a substitute from dynamic data, but i don't know if it's a best practice or not.
View 1 Repliesi've got a website that uses OutputCache attribute to cache pages. Works great.
Now, I'm in the middle of R&D'ing scaling up this site to be in a web farm. Along with the usual suspects for webfarm pain ... I've noticed (pretty quickly/obviously) that the OutputCache from Server_A doesn't invalidate the OutputCache from Server_B .. if a try and invalidate a single server's OutputCache. This makes total sense -> how can S_A 'tell' S_B to invalidate when they are physically 2 seperate machines, etc?
So - what are our options?
Velocity? I understand this will move the caching to a different layer .. which means that the final result (output) will always be required to be determined .. as opposed to the OutputCache whic remembers the final output content (yes, varby gives different versions, etc.. which is totally fine). So even though the poco or business objects are all sync'd, there's still that last rendering effort required (even if it's tiny .. compared to the effort to generate/sync business objects).
I've an action in a controller that returns different content if the request is Ajax or not:
[Code]....
So, from the view I can fill a <div> with the PartialView (RenderPartial), calling the same action (allowing javascript disabled clients). The problem is the cache, because when the request has cached as a normal request, if later sends the request as an Ajax request, the view is rendered very bad.
The question is: Is there any way to use OutputCache to allow to cache in different entries this two types of requests (Ajax and not Ajax).
I have a user control with OutputCache set to vary by any param (*). This user control has a LinkButton, which when clicked, causes a postback, and displays a ModalPopupExtender (the extender's TargetControlID is a dummy link). The user control is included on an aspx page.
The LinkButton is displaying the popup just fine. But if I open another browser tab/window/type, the LinkButton fails to generate the popup. I've tried (all separately):
moving the popup extender and its associated control to the main aspx page use OutputCache Location="None" on main page dynamically create the Popup extender and its associated control in Page_Init of both ascx and aspx
I have an IHttpHandler that I would like to hook into the OutputCache support so I can offload cached data to the IIS kernel. I know MVC must do this somehow, I found this in OutputCacheAttribute:
public override void OnResultExecuting(ResultExecutingContext filterContext) {
if (filterContext == null) {
throw new ArgumentNullException("filterContext");
}
[Code]....
I'm looking into using the OutputCache-attribute for my ASP.NET MVC website. However, my website is using resources (*.res-files) to display two different languages (based on the user's settings in a cookie and/or database setting). Is there any way I can cache actions for my two languages separately?
Setting a "VaryByHeader" isn't gonna cut it since I have lots of visitors so every second visitor has probably another language set than the visitor before him. This would cause the cached action/page to always be updated since it's a different language.
What parameters to use in OutputCache if you want to Cache in case of no params on a page, in other cases not caching?
View 1 RepliesI am using MVC 2 and am having problems getting the OutputCache to work. My ASP.NET website has Several Views and a View Master Page. On my View Master Page I have a Menu on the left hand side displaying navigation links (implemented using JQuery).
I have implemented the Menu as a PartialView and I call this PartialView from my MasterPage using Html.RenderAction. This all works fine, my controller fetches the data from the database and the PartialView is populated.
The problem is I want to cache the Menu data since it's consistent on all pages. Yet when I add the OutputCache parameter to my Action it has no effect.
** Action **
[Code]....
** Partial View **
[Code]....
** Master Page **
[Code]....
I'm using routing from System.Web.Routing without MVC in a standard ASP.Net Web Application Project application. This is mostly done to get neater urls in the portal we are developing (instead of ~/default.aspx?contentid=123 we have ~/{contentsubject}. The portal is not authorized and all info is in the url so in a caching scenario we can cache complete pages.
When I tried to enable output caching I noticed that no caching was done. It seems that the outputcache page directive is completely ignored. Is this true or am I missing something? Can this be fixed?
I made a small test app (I uploaded it to [URL] that just contains a page, Webform1.aspx, that uses a master page and a user control. All three output the current date and time.
When I request http//localhost/OutputcacheTest/Webform1.aspx the 10 second caching works as expected, i.e. the shown time only updates every 10 seconds.
The app also defines a wildcard route that catches all requests and returns the same Webform1.aspx as a handler. So when requesting http//localhost/OutputcacheTest/myroute the same page is executed but now the caching doesn't work, i.e. the current time is shown on every request.
Note: When using the built-in development web server both scenarios work, only IIS seems to have this problem.
Does anyone have a a solution or work around for how to enable output caching in this scenario?
I've got a website that has a number of host headers. Depending on the host header, the results are different - both visually (theme'd) and data.
So lets imagine i have a website called 'Foo' - that returns search results (original, eh?).
Now, the same code runs both sites. It is physically the same server/website (using Host Headers) :-
[URL]
And the data is different for the same search result, based on the host name (ie. us results for [URL] results for [URL]
SO .. if i wish to use OutputCaching .. can this be handled / differ by the host name?
I have an ASP.NET application which requires output caching. I need to invalidate the cached items when the data returned from a web service changes, so a simple duration is not good enough.
I have been doing a bit of reading about cache dependencies and think I have the right idea. It looks like I will need to create a cache dependency to my web service.To associate the page output with this dependency I think I should use the following method:
Response.AddCacheItemDependency(cacheKey);
The thing I am struggling with is what I should add to the cache?
The dependency my page has is to a single value returned by the web service. My current thinking is that I should create a Custom Cache Dependency via subclassing CacheDependency, and store the current value in the cache. I can then use Response.AddCacheItemDependency to form the dependency.
I can then periodically check the value and for a NotifyDependencyChange in order to invalidate my cached HTTP response.The problem is, I need to ensure that the cache is flushed immediately, so a periodic check is not good enough. How can I ensure that my dependant object in the cache which represents the value returned by the web service is re-evaluated before the HTTP response is fetched from the cache?
I have a master page where in one ContentPlaceHolder I put my shopping cart:
<asp:ContentPlaceHolder ID="continutMeniuContulMeu" runat="server">
asp:UpdatePanel runat="server" ID="updatePanelCos" UpdateMode="Conditional">
<ContentTemplate>
<user:ShoppingCart ID="shoppingCartControl" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:ContentPlaceHolder>
Is there any way that I can list the pages which are currently stored in the OutputCache?
Just a list of paths would do, but if there's a way to get more information about each item (expiry etc), then all the better.
I use OutputCache in an ASP.net MVC application. As developing with an active OutputCache is not very pleasant I want to disable the OutputCache on the Development Systems (local machines and development server).
View 1 RepliesI'm building an ASP.NET MVC 2 site where I'm using the OutputCache parameter heavily. However, I have a concern: using such caching may interfere with authentication.On all of my pages, I display whether the user is logged in or not. Furthermore, in some of my Views, I do filtering based on user role to determine whether or not to display some page content (for example, the Edit link on one of my pages is only shown to users in the roles of Moderator or Administrator)
View 2 Repliesi am using OutputCache on a ASP.NET Page. I set it programmatically like this in my Page_Load:
Response.AddFileDependency(cachefilepath);
Response.Cache.SetExpires(DateTime.Now.AddHours(12));
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetSlidingExpiration(false);
Response.Cache.VaryByParams["*"] = true;
Now the Page will be cached and this works fine. But i have one UserControl on the Page which shouldn't be cached. Is it possbile to disable Caching for this UserControl although the whole Page is getting cached?
The reason is that the output of this UserControl has two states and so can be different for each client according to his actions...
I would like to know if its possible to use outputcache with a querystring parameter AND a session parameter together.I'm serving location based content and the countryid is stored in a session, while other parameters as categoryid, pageindex are stored in querystring.
View 1 RepliesThe following code is not working in a partial view.
<%
// Pages always expire at midnight.
Response.Cache.SetExpires(DateTime.Today.AddHours(24));
[code]...
I am having trouble with the performance of a web site... Some SQL queries are killing the server. But, as the title of this post mention, I looked at the OutputCache page directive to improve performance of the site. Although, I came across some questions regarding this directive:
1- If I have a web-user control that declares an OuputCache directive in a page that has one too, which one will "win"?
2- What's the best pratice regarding the duration ? I'd love to have a sliding window too.
In the ASP.NET MVC site that I'm writing, I'm building a generic Error Action that is routed to by an HttpModule, following this tutorial. In this Action, I will return a View corresponding to the status code that is applied to the response inside the HttpModule (after doing this, the module transfers the request over to the Action in question).
That's all good, except that I want to implement caching. I don't want to use the OutputCache attribute without filtering/varying, because that would mean that the page would be cached once. I want the page to be cached once for every possible status code.
Is it possible to somehow filter/vary with OutputCacheAttribute's properties, so that each Response.StatusCode is cached separately?
i use accordion from ajax toolkit it work correctly when i use outputcash it gives me this error:
Microsoft JScript runtime error: 'Sys.Extended.UI' is null or not an object
[Code]....