设置cookie上的路径阻止它在http静态请求中发送? [英] setting the path on cookie prevent it being sent in http static requests?

查看:353
本文介绍了设置cookie上的路径阻止它在http静态请求中发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.net应用程序中使用cookies。有没有反正在cookie的设置到用户的web浏览器,它不会发送在http请求静态资源,如CSS,javascript或图像。或者是在此类请求中不发送Cookie的唯一方法,为此类资源设置无Cookie域。

解决方案

让我先说一下:除非每秒获取数千个请求,否则对带宽和服务器负载将最小。因此,除非你正在与一个非常高的交通网站,我不会打扰。



这样说,Path不是一个很好的选择。这是因为大多数路径都在网站的有效路径下(通常 / 是有效的动态网址,但静态是从 /

因此,创建一个子域,如 static.domain.com ,并引用您的所有静态内容。它在映射到服务器的哪个位置无关紧要,只是它被来自其他域的HTML引用。 Cookie不会被传输,因为域部分不会相同(只要在Cookie声明中不使用通配符域标识符)...


I am working with cookies in my .net application. Is there anyway in the setting of the cookie to the users web browser it wont be sent in the http request for static resources such as css, javascript or images. Or is the only way around not sending cookies in such requests, setting up cookieless domains for such resources.

解决方案

Let me start by saying this: Unless you're getting thousands of requests per second, the total effect on bandwidth and server load will be minimal. So unless you're working with a really high traffic site, I wouldn't bother.

With that said, Path is not really a good option. That's because most paths are underneath a website's valid path (usually / is a valid dynamic url, but statics are served from under /)...

Instead, I would serve static content from a different domain (it could be served by the same server, or a CDN which is preferred). So create a subdomain like static.domain.com, and reference all of your static content from there. It doesn't matter where on the server it's mapped to, just that it's referred by the HTML from the other domain. Cookies won't be transmitted since the domain part won't be the same (as long as you don't use wildcard domain identifiers in the cookie declaration)...

这篇关于设置cookie上的路径阻止它在http静态请求中发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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