2011-08-12 5 views
0

아래의 aspx 및 코드 배후에서 출력 캐싱을 프로그래밍 방식으로 사용할 수있는 경우 (코드 숨김에서 사용 가능) 작동하지 않으며 문제가 있습니까?ASP.NET 프로그래밍 방식으로 출력 캐싱이 작동하지 않습니다 -> 왜?

영문 :

<%@ 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(); 
} 

:

:

영문을 의미 691,363,210
<%@ 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> 
     &nbsp;<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(); 
} 

때문에 문제가 프로그래밍에 대해 무엇인가? 이 모든 방법이 할

+0

"작동하지 않는다"고 할 때, 날짜가 페이지에서 항상 업데이트된다는 것을 의미합니까? 아니면 다른 문제입니까? 예외입니까? –

+0

@ Graham Clark hi : 날짜가 항상 페이지에서 업데이트된다는 것을 의미합니다 (예 : 캐시되지 않습니다). – MoonLight

+0

또한 outputCaching에 대한 페이지 지시문에는 아무런 문제가 없습니다 /하지만 prorammatically!/내가 영향을 받고 machine.config 또는 루트 web.config 또는 응용 프로그램 web.config에서 뭔가를 변경해야합니까? – MoonLight

답변

1
Response.Cache 

은 뭔가를 브라우저에게 응답에서 modifiy HTTP 헤더입니다 (이 경우 modifiy에 어떻게 캐시의).

이것을 보려면 Fiddler을 사용하셨습니까?

나는, 그러나 브라우저가 계속 업데이트 할 몇 가지 이유있다 (이것은 시간이 변경되었습니다 알고 있기 때문에) ASP.net이 마지막으로 수정 된 날짜를 변경 추측 것 :

  • 브라우저가 가질 수는 캐시는 캐시 단지
  • 는 브라우저가 원하는 무엇이든 요청할 수 있습니다
  • 서버에서 새로 필요한 페이지를 결정하는 다른 방법을 사용을 삭제되었을 수
  • 을 사용할

이러한 점에 대해 조사해 보시기 바랍니다. 그러나 앱의 기능을 보장하기 위해 브라우저 캐시에 의존해서는 안됩니다.

+0

답장을 보내 주셔서 감사합니다/다른 브라우저에서 상위 코드를 테스트하지 않아도됩니다. (모두 새로 고침 버튼을 클릭하면 시간이 변경되지만 의미가 없어야합니다.) /이 코드가 작동 하는지를 알려주십시오. 너 아니면하지? – MoonLight

+0

사실 새로 고침을 누르면 대부분의 브라우저 기능이 구체적으로 페이지를 다시 요청합니다 (따라서 시간이 업데이트됩니다) –

+0

내 Q를 편집/새로 고침을 누르면 대부분의 브라우저 기능이 새로 고침됩니다. 업데이트 되야 함) ->하지만 그렇게해서는 안됩니다! UnComment의 – MoonLight

관련 문제