问题标签 [httpcookie]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
visual-studio-2010 - httpCookie 导致页面无法加载
我正在使用 VS 2010、vb.net 和 asp 3.5。我有一个简单的 default.aspx 页面
从 VS 中运行页面时,页面加载正常,但是当我构建站点并运行页面时,它没有加载..它没有给我一个错误,但没有任何显示。
这是视图源的样子
HTML>HEAD> META content="text/html; charset=windows-1252" http-equiv=Content-Type>/HEAD> BODY>/BODY>/HTML>
我取出标签中的 < 以便它显示在这里...
如果我取出 Me.lbl1.Text = cookie.Value.ToString 页面加载正常。我在页面上放的只是一些文本和标签控件。
有人有想法么
asp.net - 使用 HTTPCookie 的 ASP.NET Webforms 站点 100 年超时 20 分钟后超时
我有一个使用 Forms Auth 的网站。客户端根本不希望用户的站点会话过期。在登录页面代码隐藏中,使用了以下代码:
web.config 文件的 auth 部分如下所示:
当我登录该站点时,我确实看到cookie 被正确发送到浏览器并传回:
HttpFox 输出 http://cid-e79f8e4b07c3e30f.office.live.com/embedphoto.aspx/Public/SessionProblem.png
然而,当我离开 20 分钟左右,回来尝试在网站上做任何事情时,登录窗口再次出现。这个解决方案在我们的服务器上运行了一段时间 - 现在它又回来了。在 VS2008 中运行 Cassini 的本地开发盒上不会出现此问题。
有想法该怎么解决这个吗?
asp.net-mvc - 当他访问我们的网站时如何向客户端系统添加序列号
当他访问我的网站时,我想使用 httpcookie 向客户端系统添加 3 个串行密钥
但
序列号不同不同不一样。
当我添加第 4 个 cookie 时,会自动删除 1 个密钥。
我怎么能做到这一点。
当用户想看时,他可以看到最近的 3 个键。
您知道如何通过 asp.net mvc 网站将此 cookie 添加到客户端系统吗?
我如何将 key1 、 key 2 、 key3 添加到客户端系统。
asp.net - HttpCookie 在 session 改变或无效时不被删除
我正在创建一个 HttpCookie,只设置名称和值而不是 expires 属性,然后将其添加到响应中。很简单。cookie 按预期创建(但不持久)。问题是当会话由于某种原因发生变化时(比如网站被重建,或者我在调试时重建了我的应用程序)然后 cookie 仍然存在。我希望 cookie 仅对创建它的原始会话有效。
根据 MSDN,它说:“如果您没有为 cookie 指定过期限制,则 cookie 不会持久保存到客户端计算机,并且会在用户会话过期时过期。”
我想我不确切知道“会话过期”包含什么。我认为 cookie 会在会话过期 20 分钟后被删除。但是,如果创建它的会话由于各种原因不再存在,是否应该删除 cookie?我唯一一次看到 cookie 被删除是当用户关闭所有浏览器窗口并打开一个新窗口时。
如果这一切都是真的,我可能必须将原始会话 ID(“ASP.NET_SessionId”)存储在 cookie 中,然后根据当前会话 ID 检查它,如果它们不同,则删除 cookie 或创建一个新的.
这是代码(我的 cookie 和 MSDN 示例中的唯一区别是我在 cookie 中存储了多个值):
asp.net - 为什么使用 Response 设置后,Request 中的 Cookie 立即可用?
在页面加载中,如果您立即在下一行执行 Response.Cookies.Add(..., 您可以通过 Request.Cookies(...
我知道在幕后,cookie 是由 .net 添加到 Request.Cookies 中的,但原始请求从来没有那个 cookie。
如果我说的是对的,为什么会这样?cookie 不应该在以下请求中可用吗?对 Request.Cookies(... 的立即访问不应该为空吗?
linq-to-sql - C# Cookie 不保存其信息
Scenerio - 我正在编写一个基于您使用的登录框(database1 和 database2)的 Web 应用程序,它将您连接到相应的数据库。我已将 web.config 设置为保存两个连接字符串。在每个框的 On_Authenticate 方法上,我检查以验证用户身份,然后将基于登录框的字符串发送到名为 Authenticate user 的类中的公共变量。此公共变量检查 cookie 并从变量中获取连接字符串名称,如果 cookie 为空,它会设置一个新 cookie,使所有现有 cookie 过期并设置 cookie 值。
现在一旦完成,每次我访问数据库(使用 LINQ2SQL)时,我都会创建一个数据上下文并发送 AuthenticatedUser.ConnectionString。这将检查 cookie 并发送获取用于提取数据的连接字符串。Herer 是 AuthenticatedUser 类...
}
现在这似乎在登录的第一次点击中起作用。当我输入用户信息并逐步完成该过程时,我可以看到设置的 cookie/ 但是在我使用的第一个真正的数据库调用中,我PortalDataContext db = new PortalDataContext(AuthenticatedUser.ConnectionString);
得到一个空引用错误。它正在通过 Get 并检查 cookie 并返回一个空 cookie。这里会发生什么?
asp.net - 古怪的 cookie 行为
我的一位同事让我看看一些 cookie 行为。他创建了一个简单的 Web 应用程序,该应用程序创建了一个 cookie 并插入了一个文本字段的值,然后他检查了下一页上的 cookie 集合,以查看它已被正确插入并读回。
真的很简单。
然而,在第二页上,他注意到这不仅仅是一个 cookie,其他的则与他在本地调试的另一个 Web 应用程序相关。
我告诉他这是因为浏览器识别了 URL 并因此发送了它识别为来自那里的所有 cookie,这是正确的吗?即使本地调试服务器端口更改,它也会这样做吗?
c# - HttpCookie works locally but not on server
I am having issues with my cookie management code. On every page I look to see if a key value has been set. My problem is that looking at the cookie creates an empty cookie.
Locally, I can look at the cookie and then set the key value and all is right with the world. But when I move my code to the test server, everything behaves differently. For one, locally, only one cookie is issued (shown in chrome's tools). On the server, 2 cookies are issued with the same code.
I wrote this code about 4 years ago, and it was designed for .net 2.0 when the HttpCookie behavior was changed so that looking at the cookie created an empty one if it did not exist. Previously, in .Net 1.1 null was returned. Now I'm wondering something fundamental was changed between 2.0 and 4.0.
I should note that my local machine is Windows 7 and the server is a Windows 2003 server - not that it should make any difference. The only thing to note is that the app is running in a virtual directory on the server. Could that play a part in the issues? I'm not sure. I tried setting the path of the cookie to the path of the virtual directory with no luck.
My cookie has several layers, including a base layer for dealing directly with the http cookie, an encryption layer that can be turned on or off for debugging, and then a management layer. I'm going to share my code in the hopes I have a glaring error in my logic.
I also want to mention that I am using the FormsAuthentication cookie for something else. This cookie is for some extraneous, but required, data.
My base cookie layer:
My encryption layer (batteries not included)
And finally, the cookie management layer that wraps it all up.
There is a custom configuration along with this that helps configure the cookie(s). Here's what that looks like:
Now, my code looks something like this within my web app:
I call the property first to see if the user's ID has been set. This call is done on every page. Then on another page the user can authenticate and I set the ID into the cookie. It all works locally, but if I hit the homepage on the server (where id does the lookup on the id) and then authenticate, the cookie value is not set. It remains empty.
c# - RedirectToAction 导致在带有值的 cookie 之前设置空 cookie,从而导致“丢失”cookie
我正在使用 cookie,如果设置了 cookie,它会将用户转发到登录,否则会向他们显示错误页面(未经授权)。cookie 设置正确,如果我通过在地址栏中键入它导航到任何页面,它就可以正常工作。但是,当我使用 RedirectToAction 或 FormsAuthentication.RedirectToLogin 时,cookie 不可用,这会导致重定向无限循环。
主页 - 如果用户有 cookie,则转到登录,如果没有显示主页。
登录 - 如果用户有 cookie,则显示页面,否则重定向到主页
我的重定向是通过属性处理的。
我的主页操作如下所示
我的登录操作看起来像这样
现在,当我点击 mysite.com/ 时,重定向会导致无限循环。在调试中,属性无法从 cookie 中找到值。cookie 在请求中实际上是空白的。当我输入 mysite.com/signin 时,一切正常。有任何想法吗?
编辑
按照建议,我运行了提琴手。这是请求的样子
这是cookie信息
第一的
__RequestVerificationToken_Lw__=NNu8v2oTMX2YKQOW+JRN1LQRYPhlmPszQa8Rs1KrQp1pPxWmQO8GG7eRrzbhFZF38p05ckuLHAK3QaTIlxeFJ6POTX1woXRx/ahApLpF529inJO9mj3jSnoHqG6fthzJpoLYQL61NOCCU; 4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=P%2ffJD5CdLO0pCGU6GntaPw* =P6QAytlDVUrkQn84c9vDVg *
第二
4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=; __RequestVerificationToken_Lw__=NNu8v2oTMX2YKQOW+JRN1LQRYPhlmPszQa8Rs1KrQp1pPxWmQO8GG7eRrzbhFZF38p05ckuLHAK3QaTIlxeFJ6POTX1woXRx/ahApLpF529inJO9mj3jSnoHqG6fthzJpoLYQL61NOCCU; 4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=P%2ffJD5CdLO0pCGU6GntaPw* =P6QAytlDVUrkQn84c9vDVg *
第三
__RequestVerificationToken_Lw__=NNu8v2oTMX2YKQOW+JRN1LQRYPhlmPszQa8Rs1KrQp1pPxWmQO8GG7eRrzbhFZF38p05ckuLHAK3QaTIlxeFJ6POTX1woXRx/ahApLpF529inJO9mj3jSnoHqG6fthzJpoLYQL61NOCCU; 4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=P%2ffJD5CdLO0pCGU6GntaPw* =P6QAytlDVUrkQn84c9vDVg *
第四
4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=; __RequestVerificationToken_Lw__=NNu8v2oTMX2YKQOW+JRN1LQRYPhlmPszQa8Rs1KrQp1pPxWmQO8GG7eRrzbhFZF38p05ckuLHAK3QaTIlxeFJ6POTX1woXRx/ahApLpF529inJO9mj3jSnoHqG6fthzJpoLYQL61NOCCU; 4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=P%2ffJD5CdLO0pCGU6GntaPw* =P6QAytlDVUrkQn84c9vDVg *
这是我在地址栏中输入 /signin 时的样子
__RequestVerificationToken_Lw__=NNu8v2oTMX2YKQOW+JRN1LQRYPhlmPszQa8Rs1KrQp1pPxWmQO8GG7eRrzbhFZF38p05ckuLHAK3QaTIlxeFJ6POTX1woXRx/ahApLpF529inJO9mj3jSnoHqG6fthzJpoLYQL61NOCCU; 4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*=P%2ffJD5CdLO0pCGU6GntaPw* =P6QAytlDVUrkQn84c9vDVg *
是的,我的 cookie 是加密的。cookiename 是“4%40f0nkyBbqcTD4g9yl1J8KDNcWdqRpixrEoHLuMP2Lc*” 在我看来,重定向是在其中附加一个新的空 cookie。为什么?我不知道。
ADDITIONAL 经过调试,发现Request中确实有3个cookie。第一个是空cookie,使用名称时默认返回。集合中的第三个 cookie 设置了值。为什么将这个 cookie 附加到请求中是一个谜。我可能可以通过选择比另一个有价值的 cookie 来解决这个问题,但我宁愿修复根本问题,不管它是什么,它只发生在登录页面上。
http - 将 =、& 和冒号放在 cookie 中
可能重复:
cookie 中允许的字符
我需要在 cookie 中分隔值。所以我选择了 &'s 来分隔名称=值对,就像我在 URL 中那样。一个名字也可以有多个值,所以我用冒号分隔它们。
我的问题是这是否合法?我需要对所有内容进行 URL 编码吗?这些值里面可以有冒号,所以我想我会对这些值进行 URL 编码,以确保值中的冒号不会与分隔符冲突。我在某处读到,用撇号将整个 cookie 括起来也可以,这有意义吗?
如果这不合法,那么存储我的多个名称/值对的最佳方法是什么,这些名称/值对通常每个名称都有多个值(按特定顺序,所以我不能只复制名称/值)?