Swe*_*ndu 2 javascript cookies asp.net-mvc-3
我在 javascript 中设置了一个类似这样的 cookie
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
var loginval = slmgusername=swetha.p + slmguserpassword = 12345678;
setCookie("slmgusercredentails", loginval, 100);
Run Code Online (Sandbox Code Playgroud)
我控制我在我的 cookie 中得到这样的值
HttpContext.Request.Cookies["slmgusercredentials"].Values = {slmgusername%253Dswetha.p%2526slmguserpassword%253D12345678}
Run Code Online (Sandbox Code Playgroud)
当我试图从中获取用户名时,例如
UserName = HttpContext.Request.Cookies["slmgusercredentials"].Values["slmgusername"].
Run Code Online (Sandbox Code Playgroud)
我无法获得用户名。正如我认为的那样,这些值采用 javscript 编码格式。如何获得用户名...任何人都可以帮我找到解决方案...
这应该可以解决问题!
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++){
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
alert("Key is : " + name + " and Value is : " + value);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6620 次 |
| 最近记录: |