在 cookie 上设置路径可以防止它在 http 静态请求中发送吗?
我正在我的 .net 应用程序中使用 cookie。无论如何,在用户网络浏览器的 cookie 设置中,它不会在静态资源(例如 css、javascript 或图像)的 http 请求中发送。或者是在此类请求中不发送 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先我要说的是:除非每秒收到数千个请求,否则对带宽和服务器负载的总体影响将很小。因此,除非您正在使用流量非常高的网站,否则我不会打扰。
话虽如此,Path 并不是一个好的选择。这是因为大多数路径都位于网站的有效路径下方(通常
/
是有效的动态 url,但静态是从/
下提供的)...相反,我会提供静态来自不同域的内容(可以由同一服务器或首选 CDN 提供服务)。因此,创建一个像
static.domain.com
这样的子域,并从那里引用所有静态内容。它映射到服务器上的哪个位置并不重要,重要的是它是由来自其他域的 HTML 引用的。 Cookie 不会被传输,因为域部分不会相同(只要您不在 Cookie 声明中使用通配符域标识符)...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)...