page outputcache not working with trace

纵然是瞬间 提交于 2019-12-11 17:52:09

问题


I had put the following code in the .aspx page:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="CarWale.CarDataIO.MasterDataEntry" Trace="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Duration="10" VaryByParam="none" %>

<head runat="server">
<title>Master Data Entry</title>
<link href="/css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div> <%= DateTime.Now.ToString() %></div>
</form>
</body>
</html>

When the above page was rendered with Trace="false", the code was running perfectly as expecting. The page was getting cached and the DateTime changed after every 10 seconds as expected.

But, when the Trace="true" was applied, all the page caching was lost and the DateTime was changing everytime the page was refreshed even before 10 seconds duration was completed. This I consider a serious bug in ASP.NET framework.

Can anybody guide me where I am going wrong?


回答1:


I don't believe it's a bug but just a consequence of tracing and allowing it to output to the page.

If you use these settings for tracing in web.config it should work.

<trace enabled="true" requestLimit="1000" localOnly="false" pageOutput="false"/>

Here, pageOutput="false" will prevent the tracing from being shown on the page directly and is now only accessible with TraceViewer. To see the trace, just append \Trace.axd to the url of your asp.net page (select default.aspx to get the same result page from before ).

With pageOutput disabled, tracing will now no longer prevent output caching.



来源:https://stackoverflow.com/questions/11643831/page-outputcache-not-working-with-trace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!