更新 http://jsfiddle.net/musicisair/rsKtp/embedded/result/
Google Analytics会设置4个Cookie,这些Cookie将与该域的所有请求一起发送(并设置其子域).据我所知,没有服务器实际上直接使用它们; 它们只__utm.gif作为查询参数发送.
现在,显然Google Analytics会对其值进行读取,写入和操作,并且需要将其用于GA跟踪脚本.
所以,我想知道的是,是否有可能:
__utm*后将cookie 重写到本地存储ga.jsga.js运行后删除它们ga.js读取之前,将cookie从本地存储重写回cookie表单或者,猴子补丁ga.js在开始cookie读/写部分之前使用本地存储.
显然,如果我们想要删除__utm*cookie 那么远,我们也希望使用Async的分析变体.
我猜这次投票是因为我没有问一个问题.DOH!
我的问题是:
它可以如上所述完成吗?
如果是这样,为什么还没有这样做?
我有一个默认的HTML/CSS/JS样板模板,可以通过YSlow,PageSpeed和Chrome的审核获得近乎完美的分数.我真的在寻找一种方法来在支持本地存储的浏览器中从Google Analytics中挤出剩余的cookie字节.
javascript cookies google-analytics monkeypatching httpcookie
表单身份验证票证的另一个问题是过早到期.我需要使用滑动Expiration设置为true.我已阅读论坛并了解精度损失的问题,如果请求仅在到期时间的一半之后进行,则只会更新故障单.
问题:在我的webconfig中,我有以下内容:
<authentication mode="Forms">
<forms timeout="20" name="SqlAuthCookie" protection="All" slidingExpiration="true" />
</authentication>
<sessionState timeout="20" />
<authorization>
Run Code Online (Sandbox Code Playgroud)
只有在20分钟间隔内没有请求时,用户才必须注销并重定向到login.aspx.问题是用户正在发出请求,但仍然会被抛到登录页面.这不应该发生.我想做的是为每个请求手动重置SqlAuthCookie.
以下是我的代码.它在context.AcquireRequestState上调用.
void context_AcquireRequestState(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
ResetAuthCookie(ctx);
}
private void ResetAuthCookie(HttpContext ctx)
{
HttpCookie authCookie = ctx.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie == null)
return;
FormsAuthenticationTicket ticketOld = FormsAuthentication.Decrypt(authCookie.Value);
if (ticketOld == null)
return;
if (ticketOld.Expired)
return;
FormsAuthenticationTicket ticketNew = null;
if (FormsAuthentication.SlidingExpiration)
ticketNew = FormsAuthentication.RenewTicketIfOld(ticketOld);
if (ticketNew != ticketOld)
StoreNewCookie(ticketNew, authCookie, ctx);
}
private void StoreNewCookie(FormsAuthenticationTicket ticketNew, HttpCookie authCookie, HttpContext ctx) …Run Code Online (Sandbox Code Playgroud) 我正在使用带有旧后端的Angular 8(ASP.NET MVC 5框架),而不是核心。
我正在尝试发送网站的Cookie,因此来自角度网站的请求被认为已通过身份验证
我为此创建了一个拦截器
import { HttpInterceptor, HttpHandler, HttpEvent, HttpRequest }
from '@angular/common/http';
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor() { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const newRequest = request.clone({
withCredentials: true,
});
return next.handle(newRequest);
}
}
Run Code Online (Sandbox Code Playgroud)
这是请求的代码
private getDefaultConfiguration(): configurationsType {
return {
observe: 'response',
responseType: 'json',
headers: new HttpHeaders().set('Content-Type', 'application/json')
};
}
public async get(endpoint: string, params: HttpParams = undefined) …Run Code Online (Sandbox Code Playgroud) 我在使用FormsAuthenticationTicket创建非持久性cookie时遇到问题.我想在票证中存储userdata,因此我无法使用FormsAuthentication.SetAuthCookie()或FormsAuthentication.GetAuthCookie()方法.因此,我需要创建FormsAuthenticationTicket并将其存储在HttpCookie中.
我的代码看起来像这样:
DateTime expiration = DateTime.Now.AddDays(7);
// Create ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2,
user.Email,
DateTime.Now,
expiration,
isPersistent,
userData,
FormsAuthentication.FormsCookiePath);
// Create cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
cookie.Path = FormsAuthentication.FormsCookiePath;
if (isPersistent)
cookie.Expires = expiration;
// Add cookie to response
HttpContext.Current.Response.Cookies.Add(cookie);
Run Code Online (Sandbox Code Playgroud)
当变量isPersistent为true时,一切正常并且cookie被保留.但是当isPersistent为false时,cookie似乎仍然存在.我在浏览器窗口中登录,关闭它并再次打开浏览器,我仍然登录.如何将cookie设置为非持久性?
非持久性cookie是否与会话cookie相同?cookie信息是存储在服务器上的sessiondata中还是在每次请求/响应服务器时传输的cookie?
我有一个通过 REST 与 Web 服务器通信的 Web 应用程序,该 Web 应用程序可以在公共计算机上运行,并允许多个用户在给定的时间段内登录和注销。
所有 cookie 都是 HTTP-only,这只是一种额外的安全措施,以涵盖成功的 XSS 攻击案例。这意味着必须进行 REST 调用以强制注销。
我担心的是,当网络服务器因任何原因出现故障时(或变得无法访问,例如某处网络电缆断开连接)。当用户点击注销时,实际上无法删除 cookie。这意味着用户可能会离开 PC,同时当连接恢复或服务器恢复时另一个用户可能会出现,并继续使用以前的用户帐户。
处理这个用例的典型方法是什么?(诚然不是特别常见)。
AWS的新应用程序负载均衡器抛出错误:400 Bad Request,Request Header或Cookie Too large,awselb/2.0
如何增加aws-elb的大小.它与经典的负载均衡器配合得很好.
我一直在尝试将 sameSite = None 属性添加到我的项目 cookie 作为 Chrome 标准的一部分。我正在使用 .net 框架 4.8,它支持cookie 的sameSite(https://docs.microsoft.com/en-us/aspnet/samesite/system-web-samesite#using-samesite-in-aspnet-472-and- 48 ),但我无法从 web.config 执行此操作,如果有人遇到类似问题并解决了该问题,请提供帮助。
鉴于:
Domain 1: subdomain1.mydomain.com
Domain 2: subdomain2.mydomain.com
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码在"域1"上创建一个cookie,并尝试访问"域2"上的cookie.
我的问题是"域2"不想识别cookie.是什么赋予了?我认为问题在于.Domain属性,但是我把时间段放在前面,所以我错过了什么?
public void CreateCookie()
{
Boolean bNew = false;
HttpCookie oCookie = HttpContext.Current.Request.Cookies.Get("myData");
if (null == oCookie)
{
oCookie = new HttpCookie("myData");
bNew = true;
}
// Set the cookie value.
oCookie.Domain = ".mydomain.com";
oCookie.Secure = false;
oCookie["myid"] = "myid@whatever";
oCookie.Expires = DateTime.Now.AddDays(7);
if (true == bNew)
HttpContext.Current.Response.Cookies.Add(oCookie);
else
HttpContext.Current.Response.Cookies.Set(oCookie);
}
public String GetCookie()
{
String myid = null;
HttpCookie oCookie = HttpContext.Current.Request.Cookies.Get("myData");
if (null != oCookie)
myid = HttpContext.Current.Server.HtmlEncode(oCookie["myid"]);
return myid; …Run Code Online (Sandbox Code Playgroud) 我有一个使用预渲染服务的 nginx 配置文件,我想检查 cookie 名称 access_token 是否存在,然后提供本地角度,如果 cookie 不存在(用户未登录),则代理传递请求到预渲染服务,
这是我的 nginx 配置文件,
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=prerendercloud_cache:10m max_size=100m inactive=60m use_temp_path=off;
server {
set \$root /var/www/;
resolver 8.8.8.8;
set \$prerendercloud 'service.prerender.cloud';
listen 80;
server_name _;
location = / {
if (\$http_cookie ~* "access_token" ) {
root \$root;
try_files \$uri \$uri/ /index.html;
index index.html;
}
root \$root;
try_files \$uri @prerendercloud;
}
location / {
root \$root;
try_files \$uri \$uri/ /index.html;
index index.html;
}
location @prerendercloud {
proxy_set_header Accept-Encoding "gzip";
gunzip on;
root \$root; …Run Code Online (Sandbox Code Playgroud) httpcookie ×10
cookies ×6
asp.net ×2
c# ×2
javascript ×2
.net ×1
amazon-elb ×1
angular ×1
asp.net-mvc ×1
nginx ×1
proxypass ×1
rest ×1
samesite ×1
security ×1
setcookie ×1
web-config ×1