Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Caching Output HTML

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Smithers - 01 Dec 2007 04:20 GMT
Just wondering what it would take to cache a copy of the output HTML from a
dynamically constructed aspx page before it is sent to the browser.

Reason being: the page is constructed of a few user controls, each of which
queries a SQL Server database for their content. The content is not likely
to change frequently at all - so I'd like a way to cache the final page upon
first request. Then subsequent requests are served from the cache - with no
need to do the expensive database queries on subsequent requests for the
cached page. Logic that updates the database would clear the cache so that
no stale data would exist in the cache.

1. How can I cache a copy of the page for future use?

2. How can I serve a subsequent request for the page directly from the
cache, rather than running the aspx logic?

Thanks.
Dave Bush - 01 Dec 2007 14:39 GMT
Use the cache directive in the "<%@Page .." header at the top of the aspx
page?

Something I'm missing or are you just not familiar with this feature of asp.net?

Dave Bush
http://blog.dmbcllc.com

> Just wondering what it would take to cache a copy of the output HTML
> from a dynamically constructed aspx page before it is sent to the
[quoted text clipped - 15 lines]
>
> Thanks.
Smithers - 01 Dec 2007 16:08 GMT
<snip>

> Use the cache directive in the "<%@Page .." header at the top of the aspx
> page?
>
> Something I'm missing or are you just not familiar with this feature of
> asp.net?

I am familiar with the cache directive. Perhaps I should have included a
couple of additional facts in my OP:

Most of the pages in the site never exist on disk. Instead, I plan to build
them programmatically from scratch, via HttpModule that builds and returns
the "page" to the user. I don't understand how ASP.NET implements caching
via the cache directive when serving up plain old aspx files - so I'm not
clear on how I can emulate that behavior in my HttpModule logic that builds
and returns these dynamic pages.

Until now the 1.1 system I have been working with inserts ascx user controls
into PlaceHolder controls in an aspx page that served as a template. But now
as we migrate to 3.5, I'm wanting to intercept the aspx requests as they
come in from the browser and do *everything* programmatically - including
(1) URL rewriting, (2) page construction, (3) retrieve the HTML of the final
page, (4) cache that HTML, (5) return the HTML to the requesting browser.
Subsequent requests for the same page would return the HTML from the cache.

Step 3 is what I am unclear on. How do I get the rendered HTML of a
dynamically constructed aspx before it is sent to the browser?

Thoughts? Considerations?

Thanks.
Masudur - 01 Dec 2007 17:10 GMT
> <snip>
>
[quoted text clipped - 28 lines]
>
> Thanks.

Hi... Here is few Code exampls

protected void Page_Load(object sender, EventArgs e)
   {
       if (Session["PageOutPut"] != null)
       {
           if (Session["Counter"] == null)
           {
               Session["Counter"] = 0;
           }
           Session["Counter"] = (int)Session["Counter"] + 1;
           string PageResult = (string)Session["PageOutPut"];
           Response.Write(PageResult + (int)Session["Counter"]);
           Response.End();
       }
   }

   protected override void Render(HtmlTextWriter writer)
   {
       string PageResult = "";
       if (Session["PageOutPut"] == null)
       {
//get the html output and save it in session
           StringBuilder sb = new StringBuilder();
           StringWriter sw = new StringWriter(sb);
           HtmlTextWriter hWriter = new HtmlTextWriter(sw);
           base.Render(hWriter);
           PageResult = sb.ToString();
           Session["PageOutPut"] = PageResult;
           Response.Redirect(Page.Request.RawUrl);
       }
   }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.