加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 停止从域(也称为“无Cookie域”)设置Cookie以增加站

发布时间:2020-12-15 18:47:39 所属栏目:asp.Net 来源:网络整理
导读:我正在读 Google’s documentation关于提高网站速度。他们的一个建议是从“无Cookie域”提供静态内容(图像,css,js等): Static content,such as images,JS and CSS files,don’t need to be accompanied by cookies,as there is no user interaction with
我正在读 Google’s documentation关于提高网站速度。他们的一个建议是从“无Cookie域”提供静态内容(图像,css,js等):

Static content,such as images,JS and
CSS files,don’t need to be
accompanied by cookies,as there is
no user interaction with these
resources. You can decrease request
latency by serving static resources
from a domain that doesn’t serve
cookies.

Google然后说,最好的方法是购买一个新域名并将其设置为指向当前的域:

To reserve a cookieless domain for
serving static content,register a new
domain name and configure your DNS
database with a CNAME record that
points the new domain to your existing
domain A record. Configure your web
server to serve static resources from
the new domain,and do not allow any
cookies to be set anywhere on this
domain. In your web pages,reference
the domain name in the URLs for the
static resources.

这是非常简单的东西,除了它所说的“配置您的Web服务器以从新域提供静态资源,并且不允许任何cookie设置在该域的任何位置”。 From what I’ve read,IIS中没有设置允许您说“提供静态资源”,那么如何防止ASP.NET在这个新域中设置cookie?

目前,即使我只是从新的域名请求一个.jpg,它也会在浏览器上设置一个cookie,即使我们的应用程序的cookie设置为我们的旧域名。例如,ASP.NET设置一个“.ASPXANONYMOUS”cookie(据我所知),我们不告诉它。

道歉,如果这是一个真正的新奇问题,我是新的!

谢谢。

解决方法

如果您不从域中写入Cookie,则该域名将不会被Cookie删除。

当域被设置为仅托管资源内容,如脚本,图像等时,它们将通过来自浏览器的纯HTTP-GET请求来请求。这些内容应该是原样的。这将使您的域无味。这不能通过Web服务器配置完成。 Http是完全无状态的,网络服务器根本就不了解cookies。 Cookie是通过服务器端脚本编写或发送给客户端的。最好的办法是在IIS应用程序上禁用asp.net,classic-asp或php脚本功能。

我们这样做的方式是。

我们有一个子域设置来提供无Cookie资源。所以我们在子域上托管所有的图像和脚本。从主应用程序,我们只是通过它的url指向资源。我们通过不在该域上提供任何动态脚本或通过创建任何asp.net或php会话来确保子域保持无Cookie。

http://cf.mydomain.com/resources/images/*.images
http://cf.mydomain.com/resources/scripts/*.scripts
http://cf.mydomain.com/resources/styles/*.styles

从主域,我们只是将资源引用如下。

<img src="http://cf.mydomain.com/resources/images/logo.png" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读