cookie 的“Value”=“xxxxx,xxxxx”部分无效

六眼飞鱼酱① 提交于 2020-03-08 09:15:19

cookie 的“Value”=“xxxxx,xxxxx”部分无效 
在一些网站中有时候会遇到Cookie的值为逗号

但是在.Net中Cookie的值是不能直接使用逗号的

如果使用形如

C#代码 
1.Cookie cookie=new Cookie("name","xxxxx,xxxxx");  
Cookie cookie=new Cookie("name","xxxxx,xxxxx");

会报错

C#代码 
1.Cookie 的“Value”=“xxxxx,xxxxx”部分无效  
Cookie 的“Value”=“xxxxx,xxxxx”部分无效

解决方法:

那么在使用的时候可以将逗号替换为%2C写入Cookie中

C#代码 
1.Cookie cookie=new Cookie();   
2.cookie.Name="name";   
3.cookie.Value="xxxxx%2Cxxxx";  
Cookie cookie=new Cookie();
cookie.Name="name";
cookie.Value="xxxxx%2Cxxxx";

或者

C#代码 
1.Cookie cookie=new Cookie("name","xxxx%2Xxxxx");

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!