当我一个cookie添加到Htt的presponse

当我一个cookie添加到Htt的presponse

本文介绍了如何删除'无缓存= QUOT;设置Cookie"'当我一个cookie添加到Htt的presponse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从Web服务返回的cookie与code是这样的:

I'm currently returning a cookie from a web service with code like this:

HttpResponse response = ...;
var cookie = new HttpCookie(cookieName)
{
    Value = cookieValue,
    Expires = expiresDate,
    HttpOnly = true,
    Path = "/",
    Secure = true,
};
response.Cookies.Add(cookie);

这导致自动添加一个无缓存的指令在我的Cache-Control头:

This results in the automatic addition of a no-cache directive in my Cache-Control header:

缓存控制:公众的无缓存=设置Cookie,必重新验证,最大年龄= 60

我的客户发生由直上没有缓存响应都来处理这个指令。如果我手动删除无缓存指令它击中客户端之前,缓存的伟大工程。

My client happens to handle this directive by straight up not caching the response at all. If I manually remove the no-cache directive before it hits the client, caching works great.

我如何prevent .NET自动添加该指令含饼干的反应?

How can I prevent .NET from automatically adding this directive to responses containing cookies?

推荐答案

的Htt presponse 确定基于是否<$ C $是否应该添加该指令C>饼干集合非空。因此,如果你添加页眉手动你可以从.NET隐藏其presence:

HttpResponse determines whether it should add this directive based on whether the Cookies collection is non-empty. Therefore, if you add the header manually you can hide its presence from .NET:

response.AddHeader("Set-Cookie", String.Format(
        "{0}={1}; expires={2}; path=/; secure; HttpOnly",
        cookieName, cookieValue, expiresDate.ToString("R")));

这篇关于如何删除'无缓存= QUOT;设置Cookie&QUOT;'当我一个cookie添加到Htt的presponse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:20