asp.net的OutputCache和饼干 [英] asp.net outputcache and cookies

查看:100
本文介绍了asp.net的OutputCache和饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么,如果是有我的网页上的cookies,输出缓存不起作用!

例页

 <%@页面语言=VBAutoEventWireup =false的codeFILE =ct.aspx.vb继承=CT%GT;
<%@的OutputCache时间=600位置=服务器的VaryByParam =无%GT;!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <标题>< /标题>
< /头>
<身体GT;
    <表ID =form1的=服务器>
    < D​​IV>
      < H1>高速缓存检测和LT; / H1>
      < p n =rndout=服务器>< / P>
    < / DIV>
    < /表及GT;
< /身体GT;
< / HTML>

后面

举例code

 部分类克拉
    继承System.Web.UI.Page    保护小组的Page_Load(发送者为对象,E作为System.EventArgs)把手Me.Load
        昏暗RC作为新的随机()
        DIM氡作为整数
        RN = rc.Next()
        rndout.InnerHtml = rn.ToString        Response.Cookies(符号)(你好)=世界
        Response.Cookies(符号)。过期= DateTime.Now.AddDays(370)
        Response.Cookies(符号)。域名= Application.Get(cookieurl)
    结束小组
末级

在部署到IIS 6或7,这并不缓存,但是如果我注释掉它的3 Response.Cookies线。

在VS中跑起来,它工作正常两种方式。

有没有在IIS / web.config文件等一些设置允许的OutputCache而我设置response.cookies。据我所知,cookie的内容将被缓存以及它只是一个被缓存的HTTP响应的一部分。

感谢

Symeon。


解决方案

您尝试缓存此服务器端,并在同一时间,你尝试设置在客户端上的cookie - 这不是一起工作。

为什么:当你设置缓存页面在服务器端的code后面时,缓存版本的服务是不运行(发送到客户端)。这是在服务器高速缓存的点。不运行任何东西,从缓存给它,因为它是。

也许你只是需要设置的头缓存,而不是缓存在服务器上完整的页面。

Does anyone know why if is have cookies on my page, the output cache does not work !

Example page

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ct.aspx.vb" Inherits="ct" %>
<%@ OutputCache Duration="600" Location="Server" VaryByParam="none" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h1>Cache test</h1>
      <p id="rndout" runat="server"></p>
    </div>
    </form>
</body>
</html>

Example code behind

Partial Class ct
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim rc As New Random()
        Dim rn As Integer
        rn = rc.Next()
        rndout.InnerHtml = rn.ToString

        Response.Cookies("sym")("hello") = "world"
        Response.Cookies("sym").Expires = DateTime.Now.AddDays(370)
        Response.Cookies("sym").Domain = Application.Get("cookieurl")


    End Sub
End Class

when deployed to iis 6 or 7 this does not cache, however if i comment out the 3 Response.Cookies lines it does.

When run up in VS it works fine both ways.

Is there some setting in iis/web.config etc to allow outputcache while i set response.cookies. I understand the cookie content will be cached as well as it is just a part of the http response that is cached.

Thanks

Symeon.

解决方案

You try to cache this on server side, and at the same time you try to set the cookie on the client - this is not working together.

Why: When you set a page on cache on server side the code behind is not run when the cached version is served (send to client). This is the point of caching on server. To not run anything and give it from the cache as it is.

Maybe you need to just set the cache on header and not cache the full page on server.

这篇关于asp.net的OutputCache和饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆