在Defalut.aspx里加上
<%@ OutputCache Duration="60" VaryByParam="none"%>进行缓存并且引入了一个自己的控件:
<%@ Register Src="best.ascx" TagName="best" TagPrefix="uc1" %>
现在,我希望这个控件里的内容不被缓存,但是不知道该怎么做。哪位XD能教偶我一下啊,小弟在这里先谢啦。据说Substitutoin可以做到的,但我不知道该怎么办,最好的成果也就做到有一个字符串不被缓存。
<%@ OutputCache Duration="60" VaryByParam="none"%>进行缓存并且引入了一个自己的控件:
<%@ Register Src="best.ascx" TagName="best" TagPrefix="uc1" %>
现在,我希望这个控件里的内容不被缓存,但是不知道该怎么做。哪位XD能教偶我一下啊,小弟在这里先谢啦。据说Substitutoin可以做到的,但我不知道该怎么办,最好的成果也就做到有一个字符串不被缓存。
<%@ Control Language="C#" CodeFile="AdvancedSearch.ascx.cs" Inherits="AdvancedSearch_ascx" %>
<%@ OutputCache Duration="70" %>
<%@ Register TagPrefix="uc1" TagName="LocationDropDown" Src="~/Controls/LocationDropDown.ascx" %>
<%@ Register TagPrefix="uc1" TagName="CategoryDropDown" Src="~/Controls/CategoryDropDown.ascx" %>
<legend>Category:</legend>
<uc1:CategoryDropDown ID="CategoryDropDown" Runat="server" />
<p>
</p>
<legend>Search Term:</legend><span>
<asp:TextBox ID="SearchTermTextBox" Runat="server" CssClass="post_title"></asp:TextBox></span>
<p>
</p>
<legend>Maximum Price:</legend>$ <span>
<asp:TextBox ID="MaximumPriceTextBox" Runat="server" CssClass="post_dollars"></asp:TextBox></span>
<p>
</p>
<legend>Location:</legend>
<uc1:LocationDropDown ID="LocationDropDown" Runat="server" ShowAnyLocationChoice="True" />
<p>
</p>
<legend>Date:</legend>
<asp:DropDownList ID="DayRangeList" Runat="server" OnSelectedIndexChanged="DayRangeList_SelectedIndexChanged">
<asp:ListItem Value="-1" Selected="True">any</asp:ListItem>
<asp:ListItem Value="1">within last day</asp:ListItem>
<asp:ListItem Value="2">within last 2 days</asp:ListItem>
<asp:ListItem Value="7">within last 7 days</asp:ListItem>
<asp:ListItem Value="30">within last month</asp:ListItem>
</asp:DropDownList>
<p>
</p>
<legend>Show:</legend>
<asp:DropDownList ID="AdTypeList" Runat="server" OnSelectedIndexChanged="AdTypeList_SelectedIndexChanged">
<asp:ListItem Value="0">All Types</asp:ListItem>
<asp:ListItem Value="1">For Sale only</asp:ListItem>
<asp:ListItem Value="2">Wanted only</asp:ListItem>
</asp:DropDownList><p>
</p>
<asp:CheckBox ID="PhotoCheckBox" Runat="server" Text="with Photo(s)" /><br />
这样子的话,用户组件也会被缓存70秒,我现在希望插在页面里的用户控件是实时更新的,而页面除了控件部分是缓存的啊。
缓存很简单,我是想实现部分缓存。再解释一下:是整个页面除我的控件以外缓存,只有我的控件不被缓存,每次刷新,内容都会改变。
下面是答案:
http://msdn2.microsoft.com/zh-CN/library/ms227429.aspx
Response.WriteSubstitution的方法,参数可以是“a method, user control or object to substitution”,但是,这地方只要一写我的控件名称,就出现异常:
cannot convert from 'ASP.best_ascx' to 'System.Web.HttpResponseSubstitutionCallback'
参数类型出问题了,这个参数应该传什么啊?
对你需要缓存的控件,进行 fragment cache 。试试
用Fragmnet cache只能缓存控件,而我想实现的是缓存后替换!!!