UserControls - Programmatically Setting Output Caching Duration?
Apr 7, 2010
I want duration to be configurable from Web.config file, so user can alter the output caching after deployment.
For achieving such puropse i need quuivalent C# codebehind snippet of following ASP.NET markup?
<%@ OutputCache Duration="120" VaryByParam="CategoryName" %>
View 2 Replies
Similar Messages:
Mar 22, 2010
UserControl: How to set Output Cache duration programaticaly?
View 2 Replies
Feb 16, 2010
Programmatically Loading UserControls with Page_load Event?
View 2 Replies
Apr 7, 2010
I have a page with outputcache right above the action in a controller class. What I want is to disable this outputcache for myself. Can it be done by IP?
Something like that: [OutputCache(Duration = 60, VaryByParam = "None", IgnoreIP = "100.100.100.100")]
View 6 Replies
Sep 21, 2010
I plan to use output cache for my page and also specify sql dependencyi succeded in doing it the following way
[Code]....
Suppose if i want to implement a dependency on the sql query , i create an sqlcache dependency object and specify the sql command to it.Set the notifications .But how do i add this sqldependency to the output cache?For example: if i need to add a file dependency, i give something like Response.AddFileDependency ("filepath"); is there any similiar command available for sqldependency as well? I'm confused about this because, most of the examples i've looked into, does a cache.insert , which defeats my purpose as it's object caching and not output caching. In a nutshell, is it possible to attach a sqlcachedependency to o/p cache inside the controller action
View 3 Replies
Jan 28, 2010
Does output caching help boost the performance of asp.net mvc pages that just consist of html, css, images, and javascript?
View 1 Replies
Jan 11, 2010
I have a user control (say PricingGrid.ascx) which generates a pricing grid on a given product's page. I pass the user control 2 parameters : currencyId and productId. The user control has output caching specified by
[Code]....
I am adding PricingGrid.ascx to my page programatically, i.e. using LoadControl [URL]If the user changes their currency and refreshes the page, the cached version of their original currency is still showing, until the 60 seconds expires. Is there any way to force the page to check :1) Does a cached version of PricingGrid.ascx with their new currency exist?2) If so, retrieve that version, and if not, create that version.If I output all the keys in the Page.Cache object on PageLoad, I'm not seeing my user control in the output.
View 3 Replies
Jun 8, 2010
I'm using output caching in my custom HTTP handler in the following way:
public void ProcessRequest(HttpContext context)
{
TimeSpan freshness = new TimeSpan(0, 0, 0, 60);
context.Response.Cache.SetExpires(DateTime.Now.Add(freshness));
context.Response.Cache.SetMaxAge(freshness);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetValidUntilExpires(true);
...
}
It works, but the problem is that refreshing the page with F5 leads to page regeneration (instead of cache usage) despite of the last codeline:
context.Response.Cache.SetValidUntilExpires(true);
UPD: Seems like the cause of problem is that HTTP handler response isn't caching on server. The following code works well for web-form, but not for handler:
Response.Cache.SetCacheability(HttpCacheability.Server);
Are there some specifics of the caching the http handler response on server?
View 2 Replies
Apr 9, 2010
Iam adding SqlCacheDependency programmatically but Iam not able to invalidate the cache.
Iam using the following Output cache directive in the .aspx page
[Code]....
The code in the .aspx.cs file is:
[Code]....
View 1 Replies
Sep 30, 2010
I've seen a number of options for adding GZIP/DEFLATE compression to ASP.Net MVC output, but they all seem to apply the compression on-the-fly.. thus do not take advange of caching the compressed content.
Any solutions for enabling caching of the compressed page output? Preferably in the code, so that the MVC code can check if the page has changed, and ship out the precompressed cached content if not.
This question really could apply to regular asp.net as well.
View 3 Replies
Mar 4, 2011
I have a page which contains a user control. The structure of the page is as shown below:
Incase your not able to see the above image, check it at [URL] Now, apart from the contents of the UserControl, I'd like to cache the entire page. I tried using the OutputCache attribute in the .aspx page, however it caches the contents of the UserControl as well.
View 4 Replies
Jan 10, 2011
Output Caching .NET 4 on any view. But I can't extend the output caching (on a disk) for a partial view(RenderAction).
View 1 Replies
Jul 9, 2010
Ive tried [OutputCache] for a view that is rendered from Html.RenderPartial, but it doesn't work! It works perfectly for 'normal' views.
How do I cache output for partial view?
View 2 Replies
May 17, 2010
I would like to use output caching with WCF Data Services and although there's nothing specifically built in to support caching, there is an OnStartProcessingRequest method that allows me to hook in and set the cacheability of the request using normal ASP.NET mechanisms.
But I am worried about the worker process getting recycled due to excessive memory consumption if large responses are cached. Is there a way to specify an upper limit for the ASP.NET output cache so that if this limit is exceeded, items in the cache will be discarded?
I've seen the caching configuration settings but I get the impression from the documentation that this is for explicit caching via the Cache object since there is a separate outputCacheSettings which has no memory-related attributes.
Here's a code snippet from Scott Hanselman's post that shows how I'm setting the cacheability of the request.
[code]....
View 1 Replies
Apr 22, 2010
I am trying to use output caching on my .net pages but it is not working when I use Route handlers to redirect request to actual page, but it works when I call the page directly.
also one more weird thing is that when I am debugging and using .net instance of IIS http://localhost:64293/test it is working, but when I deploy it and try to call the page it is not caching i.e. http://www.mydomain/test(but it works if I call the page directly)
I am using VS 2010, IIS 6.0, .net Framework 4
aspx page code is :
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" Title="Not Found" %>
<%@ OutputCache Duration="300" VaryByParam="*" Location ="Server" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
litPageTitle.Text = "<br/>Datetime: " + DateTime.UtcNow.ToString();
}
</script>
my global.asax.cs code is
public static void RegisterRoutes(RouteCollection routes)
View 2 Replies
Feb 25, 2010
I have a need to run an application in classic mode for backwards compatibility with a specific application, and am trying to understand what kind of impact that will have on the performance of an MVC application that is running on the site. If we put a few static file maps (for .js, .css, .png, etc) above the ASP.NET wildcard map to reduce the amount of processing by the ASP.NET handler, will we be approaching the integrated mode in terms of performance?
The thing i'm primarily concerned with is any effect this might have on output caching. I understand that integrated mode might (?) allow for the output cache to handle non ASP.NET content, but that isn't really a concern. We're more interested in ensuring that the MVC application has full use of the output cache. Empirically i've found that the two configurations operate on par when things go well, but if the page references resources that are not available, the integrated mode tends to fail much more quickly than the classic mode (e.g. 500 ms vs 10 seconds), reducing 'hang time' on the page load.
View 1 Replies
Feb 3, 2010
I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at [URL] However, I noticed that Page Caching no longer works after the first Response.Flush call.
I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set. So it seems that Response.Flush completely undermines any page caching in use. Why is this?
extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?
ASPX Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>
Code-behind (Page is Cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
Code-behind (Page is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Flush();
}
Code-behind (Page still is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Flush();
}
View 1 Replies
Jul 13, 2010
I'm trying to cache user controls and on some pages i want to cache single objects. There are multiple ways of implementing caching, and my head is breaking over it.
The way I see the caching options now:
You have the PartialCaching option which is set to cache the control for 30 minutes, and after that it clears itself... You have the varyByParam to identity the page by its querystring paramaters... or other vary options
But i just cant find an appropriate way to add caching to a control, and be able to clear the caching programmatically when i update one of the objects used in the control from the backend.
You can do HttpContext.Current.Cache.Insert(), which accepts a key on which you can destroy the caching item later by using remove... This can save objects in cache but can you use options like varyByParam?
My questions are burnt down to two:
Is there a way to clear the caching on specific user controls from the code? If yes, can this be done according to the varyby options? How would the object caching respond to logged in users or anonymous users using Insert()?
EDIT: I'm caching multiple things.... And I'm really flabbergasted in which choice to make referring to caching. Can the Cache.Insert be varied by Parameters?
The main problem is peopling editing things from the backend, which needs to trigger an event that reinstantiates or clears all caching items referring that object.
View 2 Replies
Sep 13, 2010
I have an ASP.Net site (happens to be MVC, but that's not relevant here) with a few pages I'd like cached really well.
Specifically I'd like to achieve:
output cached on the server for 2 hours.if the file content on the server changes, that output cache should be flushed for that page
cached in the browser for 10 minutes (i.e. don't even ask the server if it's that fresh)when the browser does make an actual subsequent request, I'd like it to use etags, so that the server can return a 304 if not modified.
(note - time values above are indicative examples only)
1) and 2) I can achieve by Response.Cache.SetCacheability(HttpCacheability.Server)
I know 3) can be achieved by using max-age and cache-control:private
I can emit etags with Response.Cache.SetETagFromFileDependencies();
but I can't seem to get all of these things to work together. Here's what I have:
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetETagFromFileDependencies();
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetMaxAge(TimeSpan.FromSeconds(60 * 10));
In particular:
can browsers do both 3) and 4) like that? When Firefox issues a new request after it expires in the local cache, it does indeed send the etag the server responded with before, but I get a 200 response.setting the variables like above, where would I set the duration of the output caching?
View 1 Replies
Apr 15, 2010
I want to use an Enum value for the types of VaryByCustom parameters I will support, is it possible to do this?
I tried setting it in the page itself
<%@ OutputCache Duration="600" VaryByParam="none"
VaryByCustom='<%=VaryByCustomType.IsAuthenticated.ToString(); %>' %>
But this returned the entire literal string "<%=VaryByCustomType.IsAuthenticated.ToString(); %>" inside my global.asax is there any way to do this either on the page itself or from the codebehind? Or is this just something I have to accept is purely magic strings and nothing I can do to add type safety to it?
View 1 Replies
Aug 13, 2010
I have a problem setting focus on a usercontrol in asp.
I have a masterpage with a script manager and a few contentpages. On two of the contentpages I have a usercontrol. Inside this control I have a updatepanel that has another usercontrol that has a asp:textbox, aka TheTextBox. I need those pages to set the focus to TheTextBox.
The innermost usercontrol sets focus in page_prerender: ScriptManager.GetCurrent(Page).SetFocus(TheTextBox);
Now this works on the first pageload, and the second. But not on the third load! And i cant really understad why, but I'm guessing that its because the 2nd postback is renderd inside an updatepanel and somehow that cause the setfocus to not trigger propperly after the 2nd postback.
View 1 Replies
Nov 22, 2010
Trying to output the PageName in a masterpage.
Masterpage has a Literal in which I am setting by accessing a property on the MasterPage "PageTitle".
<head runat="server">
<title><asp:Literal ID="litTitle" runat="server"/></title>
<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
The child page is like this:
<asp:Content runat="server" ContentPlaceHolderID="content">
<%
MasterPage master = Master as MasterPage;
master.PageName = "Log in";
%>
</asp:Content>
And the property PageName is coded thusly:
private string _pageName;
public string PageName
{
get
{
return _pageName;
}
set
{
_pageName = value;
litTitle.Text = _pageName;
}
}
I'm guessing this is because the page output has already been rendered, but as I say I don't know enough about ASP.NET. I guess I'm after something similar to PHPs ob_start().
View 2 Replies
Aug 27, 2010
I have set the output cache for 5 pages(5 minutes)
I want to clear all these pages from cache on some nutton click
View 2 Replies
Jul 23, 2010
I can check the value of a checkbox in a GridViewRow:
isChecked = CType(row.FindControl("chkSelect"), CheckBox).Checked
But what's baking my noodle is trying to figure out how to programmatically set a checkbox to checked.
The scenario is I have some rows in a GridView that are associated to another value in a dropdown. So, when I select the value in the dropdown, I'd like the checkboxes in the GridViewRows that are associated with that value to be already checked.
Problem: The check value is not persisted in the database. There's no field for it. The checkbox on the GridViewRows is an ASP TemplateField.
So I iterate through the rows and would like to check whichever checkboxes I need to based on whatever condition.
View 1 Replies
Jul 28, 2010
I am using YAF as my online forum. I've synched user account databases between YAF and my own application, but call 'Membership.Providers["YafMembershipProvider"].CreateUser' at the same time as I create my own members. However, there's a problem... My users are identified by email address for logon. So now the forum shows everyone's email addresses.
YAF has an option called 'display name'. Is it possible to programmatically create this as well?
View 1 Replies