Render Output To String - Response.Flush Breaking Page Caching

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


Similar Messages:

Web Forms :: Response.Flush() | Response.Buffer = False: Neither Do Anything?

Sep 20, 2010

So,I have this code:

[Code]...

Even though I have buffer set to false,no text is displayed.I have tried adding a response.flush,with and without changing the buffer value.What exactly is wrong?I've also tried it with and without the label(i.e. with or without just Response.Write)

View 2 Replies

How To Handle Response.flush

Jun 21, 2010

I am using Response.flush() method for download the csv file. I am create the html on page and call the Response.flush method. It is working good But when i am cancel the download and do the another operation , It genrates the error.

View 6 Replies

MVC - Enabling Caching Of The Compressed Page Output?

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

Output Caching A Page Except A User Control In It?

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

Render Page Into Custom Output?

Jan 31, 2011

Letīs take an usual aspx page, ~/admin/template.aspx

The admin folder allows only "Admin" roles for example.

Now I donīt want to run the template.aspx as usual, but I want it be called from a active process. Letīs say Iīm on ~/admin/buildMyStuff.aspx and there Iīm collecting some data, I now have some querystring, like "?do=this$andDo=that$index={0}". Now I want, using this template, loop through my data and generate my ouput, putting it then for example in a static html or in a text file or something else.

How should I do that? Calling it as new request, waiting for response? What I have to do, that it is running under the "Admin" role, or is it doing it automatically, since I already am admin?

Or is there another possibility, that allows me to run the template page and specifiing my custom htmltextwriter as output?

EDIT:

public static string RenderPageAndGetHtml(string pageUrl, string pageQuery)
{
var sw = new StringWriter();
var wr = new SimpleWorkerRequest(pageUrl, pageQuery, sw);

[Code]....

View 3 Replies

Use Of Response.Flush Before Response.End

May 12, 2010

When to use Response.Flush? Do I need to call it every time before I call Response.End?

View 2 Replies

Caching Asp.net Page Response On Client Side?

Mar 3, 2011

I am trying to cache asp.net page response on client Browser by adding following cache headers

Response.Cache.SetExpires(DateTime.Now.AddMinutes(10));
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);

With the above headers it is not working.. May I know what else to be added?

I am using jquery from client side to get the page response

View 1 Replies

Web Forms :: Response.Write Breaking CSS?

Jan 5, 2010

I have an aspx page and when the user clicks a button the following code runs:

Response.Write(string.Format("<script language='javascript'> window.open('DisplayImage.aspx?DocumentID={0}', 'window','HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes');</script>",
id));

The variable id is declared and it's value set eralier in the method.When the new window opens it displays the image properly, but the existing page suddenly loses all of it's styling. The links double in size and change font family. Does anyone know a way to retain styling on the calling page?

View 3 Replies

Web Forms :: How To Get Output HTML And TransmitFile As The Response To An Page

Nov 18, 2010

I'm trying to create an ASPX page that displays both an HTML message ("Please wait, your file transfer will begin momentarily") and also commence transmitting a file. I'm trying to avoid making the user open the page, and then clicking a Download buttonIt seems like this may be possible with a "Multipart/mixed" MIME type. Elsewhere I think I read that ASP.NET won't support this.

[Code]....

View 3 Replies

How To Fetch Output Of Page As String

Feb 9, 2011

I want to fetch output as string. I want to run webpage from my code like [URL]after running i want to keep whole values in a string and again in next step i want to search all anchor href values from the string. But initially how will get domain ouput as string ASP.net.

View 1 Replies

MVC :: Output Caching For Several Client IP's

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

How To Render A Dynamic Page Only To A Text String To Then Be Able To Email It

May 20, 2010

Is there a way that I can create a page and master page and have some of the values dynamicly loaded thru selecting items in the querystring parameters.....

then is there a way that I can render that page only to a text string? by calling it with some querystring parameters and have it render to a string?

I guess my question is only the second part as I already know how to create a page with masterpage etc...

I also know how to create an email and snd it. I just dont know how to render the page to a string

I guess what I mean is that I want to render the page on the server in code behind and then have a text string which would be the rendered HTML in a string variable of some sort... I dont want to render the page to a users browser... in fact there would be no user at all connected (there is no need to be)What I want to do is (in a code module) load up a page created and stored in my wed app directory. I want to be able to load it from a code module and to bhe able to load it with some parametsrs and just get the rendered HTML.

I am trying to write a module which will send a HTML email to registered users and I want that HTML to be dynamicly created depending on some values in the recipient user,s profile.

View 3 Replies

Web Forms :: Render Page To String In Separate Thread?

Feb 24, 2010

I've got a page that I'm using as an e-mail template. I'd like to spin off a new thread, take the rendered page, and put it into an e-mail. Is this possible? If so, how? I haven't had luck so far.

View 3 Replies

.net String Formatting - Non Breaking Space

Mar 4, 2010

DateTime.Now.ToString("h:mm tt")

What is the proper way to.. escape if that is the proper term, that html entity so that it will produce the output Code: 8:53 am and the non breaking space is rendered correctly be the browser?

View 1 Replies

Caching - Cache Render Of Calendar Control?

Sep 8, 2010

We display an ASP.NET calendar control and update the color and if the day is enabled with the DayRender event. This process is a bit slow so I'm trying to map out a strategy to cache the results of the all the DayRenders. Basically take a snapshot of the calendar and cache it for X minutes. Where would I hook into the page/control workflow to accomplish this goal?

View 1 Replies

Generating Output Through Query String In The Same Page

Jan 17, 2011

I have an ASP.NET website in which I have to perform a certain operation. I have to displaying the ID's from the DB on menu.aspx page in this format {1:2:3:4}. The above format is not a problem and can be just be written with

[Code]....

But here comes my question. I have to generate this ID when the user types the query within the URL somewhat like

[Code]....

Note that I am saying that user will type this URL. I know that query string can pass the values from one form to another but this is a single web form and if I attach this [Code].... , it should return the result. How can this be done?

View 3 Replies

MVC :: Output Caching And Query Dependency?

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

Output Caching On Static Pages?

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

Web Forms :: User Control Output Caching?

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

Output Caching In HTTP Handler And SetValidUntilExpires?

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

State Management :: Using SqlCacheDependency With Output Caching?

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

Load Up A Asp.net Page Object And Render Its Contents To String From A Console Application?

Feb 9, 2011

I am trying to use aspx pages as an email templates. There will likely be a bunch of objects on the page which will be used as replacements in the html. Because it's an aspx page I'll be able to use databinding, repeaters, etc. At run time, I want to be able to instantiate the aspx page from its path, pass in a bunch of properties, and then get the rendered result of the page and email it. This seems pretty straightforward from a asp.net website (maybe using BuildManager or Server.Execute.) However, I want to be able to use the same templates via a console application by just loading up a page object from its filepath. Is this possible?

View 1 Replies

MVC :: Controller.UpdateModel Breaking Change On Empty String?

Apr 22, 2010

I have just upgraded a large project to MVC 2 (50+ controllers) and whilst the project builds fine I am having issues in several places because it looks like the way the Controller.UpdateModel method handles emtpy strings has changed.

In MVC 1 it set the associated property to an empty string but in MVC2 it's setting it to null.

View 2 Replies

MVC :: Can't Extend The Output Caching On A Disk For A Partial View

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







Copyrights 2005-15 www.BigResource.com, All rights reserved