我在 ASP 中创建了一个名为 language
的 cookie,它被设置为字符串 "VBScript"
。我已将一个 Expires
属性附加到该属性,其值为 #May 1,2016#
。我能够检索 cookie 的值,但在检索过期日期时遇到问题。这是 ASP 代码:
<%
response.write("Cookie: " & Request.Cookies("language")) ' outputs 'VBScript'
response.write("Expiration Date: " & Request.Cookies("language").Expires) ' possible line of error
%>
当我运行此代码时,Cookie 值旁边显示“处理 URL 时发生错误”。请联系系统管理员。如果您是系统管理员,请单击此处了解有关此错误的更多信息。 “此处”部分是 Microsoft 网站的链接。我可能会考虑删除“可能的错误行”,但是在这种情况下有没有办法检索 cookie 的过期日期?
更新:
删除“可能的错误行”只是删除错误消息并仅显示 cookie 的值。
最佳答案
来自:Response.Cookies Collection
Expires
Write-only. The date on which the Cookie expires. This date must be set in order for the Cookie to be stored on the client's disk after the session ends. If this attribute is not set to a date beyond the current date, the Cookie expires when the session ends.
它是一个只写值,无法从中读取。
还有Request.Cookies集合没有名为 Expires
的键。
关于cookies - 如何检索 ASP cookie 的 'Expires' 属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36826059/