开发者

setting the path on cookie prevent it being sent in http static requests?

开发者 https://www.devze.com 2023-02-07 00:47 出处:网络
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 a

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)...

0

精彩评论

暂无评论...
验证码 换一张
取 消