问题描述
我在.net应用程序中使用cookies。有没有反正在cookie的设置到用户的web浏览器,它不会发送在http请求静态资源,如CSS,javascript或图像。或者是在此类请求中不发送Cookie的唯一方法,为此类资源设置无Cookie域。
让我先说一下:除非每秒获取数千个请求,否则对带宽和服务器负载将最小。因此,除非你正在与一个非常高的交通网站,我不会打扰。
这样说,Path不是一个很好的选择。这是因为大多数路径都在网站的有效路径下(通常 /
是有效的动态网址,但静态是从 / $ c $相反,我将为来自不同域的静态内容提供服务(可以由同一服务器提供,也可以由首选的CDN提供)。
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静态请求中发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!