请问如何在ASP.NET中用C#获取javascript注册的cookie值? 采用Response.Cookies["pro_str"].Value,返回值是NULL?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 注意Cookie的path如果Path不同是不能取到值的最好用Firefox测试工具->选项->隐私->现实Cookie先确认Cookie是否存在,之后再核对Path JAVASCRIPT是这样定义COOKIE的 function writeCookie(name, value, hours){ var expire = ""; if(hours != null){ expire = new Date((new Date()).getTime() + hours * 3600000); expire = "; expires=" + expire.toGMTString(); } document.cookie = name + "=" + escape(value) + expire; }好像没涉及到Path啊,怎么注意这个Path呢? cookie值是存在的,因为我把cookie里面的数据实时显示在页面上的。我是在一个BUTTON的click事件里面取这个COOKIE值的。 和使用什么东西存的没有关系吧都是cookie,一样的取法,和c#存的一样的取法吧 我在C#中是这样读取的,系统能执行到//处,表明COOKIE存在,但是执行tmp = myReadCookie["pro_str"].ToString()时系统报错, 说"未将对象引用设置到对象的实例"! string tmp=""; if (Request.Cookies["pro_str"] == null) { } else if (Request.Cookies["pro_str"] != null) { HttpCookie myReadCookie = this.Request.Cookies["pro_str"]; if (myReadCookie != null) { ////////// tmp = myReadCookie["pro_str"].ToString(); } } 问题是这样的,我不小心写错了,最后一局应该这样写:tmp = myReadCookie.Value;但是这样的结果就是tmp 取出来的值是乱码,估计要解一下密. C#中Application类 如何获取GridView中的值 C#高手进来,根据进程操作窗体显示隐藏 Web服务器 急求解决办法:从ODBC引入文本数据源插入DataSet出现乱码. 请问visual studio 2005怎样使用相对路径?? 为什么我用MSDN2003的时候会弹出让我安装office2003? easyui 获取指定行号的列值 请教,如何从asp.net(vb)"快速"转入asp.net(C#),关键要快到可以开发工程? 如果移动没有标题栏的窗口? StreamReader读eml文件问题!急! 如何遍历嵌套类的属性
如果Path不同是不能取到值的
最好用Firefox测试
工具->选项->隐私->现实Cookie
先确认Cookie是否存在,之后再核对Path
function writeCookie(name, value, hours){
var expire = "";
if(hours != null){
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
}
好像没涉及到Path啊,怎么注意这个Path呢?
我是在一个BUTTON的click事件里面取这个COOKIE值的。
都是cookie,一样的取法,和c#存的一样的取法吧
if (Request.Cookies["pro_str"] == null) { }
else if (Request.Cookies["pro_str"] != null)
{
HttpCookie myReadCookie = this.Request.Cookies["pro_str"];
if (myReadCookie != null)
{
//////////
tmp = myReadCookie["pro_str"].ToString();
}
}
但是这样的结果就是tmp 取出来的值是乱码,估计要解一下密.