Cached, shared server control in asp.net appears multiple times on page

408 Views Asked by At

My asp.net website is using server controls to improve performance by caching parts of pages.

It's working fine most of the time but occaisionally, one of the server controls will appear more than once on a page - sometimes twice and sometimes three times - even though the control is referenced only once on the page.

When it happens, it looks the same from multiple computers in our office - so it's not a browser issue.

If we re-upload the .ascx file for the offending duplicating control, it fixes it. My guess is that somehow the server-side cache of the control has gone wrong and re-uploading the ascx file purges the server cache so it can be re-created afresh when the page is next requested.

My questions are:

  1. Has anyone else experienced this?
  2. Is there a way to fix it?

The directives at the top of the .ascx file are as follows:

<%@ OutputCache Duration="86400" Shared="true" VaryByParam="none" %>
<%@ Control Language="VB" ClassName="Banner_LocalGuides" EnableViewState="false" %>

The control is registered on the content page like this:

<%@ Register TagPrefix="tymControls" TagName="LocalGuides" Src="~/Banner-LocalGuides.ascx" %>

The tag is then used on the content page like this:

<tymControls:LocalGuides ID="LocalGuides" runat="server" />

One thing I considered was that it might be something to do with the timing of the application pool's recycling period in IIS compared with the OutputCache Duration attribute of the ascx file - but I may be totally wrong. The app pool recycle time is currently 240 mins (14,400 seconds).

Further info on our site setup:

  • Running asp.net 4 in classic pipeline mode.
  • IIS 7
  • Coded in vb.net
  • Using master pages, but the .ascx is referenced from the content pages not the master pages

Any help much appreciated.

1

There are 1 best solutions below

0
On

We found that the answer was in the data that the ascx control was displaying. Some of the data contained HTML which was mucking up the formatting of the page.

We ran some string functions to strip out the HTML and that fixed the problem.

The intermittent nature of the problem was due to the data changing all the time and when we re-uploaded the ascx file it forces the cached control to fetch new data - if that new data doesn't contain the HTML that was causing the problem then it appeared fixed.

Thanks for your input everyone.