gpt4 book ai didi

javascript - 将 cookie 写入 ashx 文件

转载 作者:行者123 更新时间:2023-11-30 16:54:07 24 4
gpt4 key购买 nike

我尝试在 ashx 文件中写入新的 cookie,但出现错误

 HttpCookie cookname;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];

string filename = "~/img/" + "111" + file.FileName;
filenames.Add(filename);
file.SaveAs(context.Server.MapPath(filename));
cookname["filename"] = filename;
Response.Cookies.Add(cookname);

}

我如何在 javascript 中获取 cookie?谢谢

最佳答案

你必须先初始化 HttpCookie ,名称如下

HttpCookie cookName = new HttpCookie("yourCookieName");

然后随心所欲地增加值(value)

cookName["yourPropertyName"] = value; 

要在 javascript 中获取 cookie,可以使用以下函数

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}

然后调用函数获取cookie之类的

getCookie("yourCookieName=yourPropertyName")

关于javascript - 将 cookie 写入 ashx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com