なぜ、以下のaspxとコードの背後に、出力キャッシュがプログラムで有効になっている(コードビハインドで有効になっています)、機能しないと問題がありますか?ASP.NETプログラムで出力キャッシュを有効にすることができません - >なぜですか?
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="ProgrammaticOutputCaching"
CodeBehind="ProgrammaticOutputCaching.aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblDate" runat="server" Font-Bold="False" Font-Names="Verdana" Font-Size="XX-Large"></asp:Label><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Refresh" />
</div>
</form>
</body>
</html>
コードの後ろに:問題はありません出力キャッシュ用のページディレクティブで
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.Public);
// Use the cached copy of this page for the next 60 seconds.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
//Response.Cache.VaryByParams.IgnoreParams = true;
// This additional line ensures that the browser can't
// invalidate the page when the user clicks the Refresh button
// (which some rogue browsers attempt to do).
Response.Cache.SetValidUntilExpires(true);
lblDate.Text = "The time is now:<br>" + DateTime.Now.ToString();
}
:
:は
のaspxを意味します背後
<%@ Page Language="C#" AutoEventWireup="true" Inherits="OutputCaching" CodeBehind="OutputCaching.aspx.cs" %>
<%@ OutputCache Duration="60" VaryByParam="Name;Age" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblDate" runat="server" Font-Bold="False" Font-Names="Verdana"
Font-Size="XX-Large"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Refresh" />
</div>
</form>
</body>
</html>
と
コード:
protected void Page_Load(object sender, EventArgs e)
{
lblDate.Text = "The time is now:<br>";
lblDate.Text += DateTime.Now.ToString();
}
ので、プログラムについての問題は何ですか?
「動作しません」と言われると、ページ上の日付が常に更新されている(つまりキャッシュされていない)、または別の問題があります(例外ですか?) –
@Graham Clark hi:日付が常にページ上で更新されている(つまり、キャッシュされていない)ことを意味します。 – MoonLight
また、私はoutputCachingのpageディレクティブには問題ありませんが、prorammatically! /私は影響を得るためにmachine.configまたはルートweb.configまたはアプリケーションweb.configの何かを変更する必要がありますか? – MoonLight