惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
P
Privacy International News Feed
Security Latest
Security Latest
H
Hacker News: Front Page
T
Tenable Blog
The Hacker News
The Hacker News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security @ Cisco Blogs
Project Zero
Project Zero
O
OpenAI News
AI
AI
Spread Privacy
Spread Privacy
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Scott Helme
Scott Helme
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
NISL@THU
NISL@THU
A
Arctic Wolf
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
N
News and Events Feed by Topic
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
Simon Willison's Weblog
Simon Willison's Weblog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
L
LINUX DO - 最新话题
U
Unit 42
S
Security Affairs
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
月光博客
月光博客
Engineering at Meta
Engineering at Meta
腾讯CDC
F
Full Disclosure
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
The Cloudflare Blog

博客园 - 陳龑

怎么把网站全站变黑白(如地震哀悼网站变黑白), 要兼容所有主流浏览器 学习新技术的 10 个建议 解决 PHP Fatal error: Call-time pass-by-reference has been removed mysql下float类型使用一些误差详解 windows 如何查看端口占用情况 Page类与Control类的生命周期(life cycle)比较总结[转] WCF中的Dispose[转] 面向程序员的数据库访问性能优化法则 http https无缝切换 ADO.NET 的最佳实践技巧 模板引擎的一种实现 虚拟主机时常出现MAC验证失败错误之解决方法(转) 转载 软件架构师应该具备的素质(Enterprise Solution Architects and Leadership) .NET面试题,看看你的水平[转] - 陳龑 - 博客园 js在firefox中的问题 - 陳龑 - 博客园 静态构造函数 “提高一下dotnet程序的效率一”中关于exception的问题 在VS2005中使用原来的IIS调试Web程序(像VS2003一样) 用正则表达式提取url中的Querystring参数 - 陳龑 - 博客园
asp.net Cookies 转码的问题 中文丢失 - 陳龑
陳龑 · 2008-08-27 · via 博客园 - 陳龑

 因为asp.net使用UTF-8的文字编码来显示GB2312的中文,所以有的时候会出现乱码,尤其在cookies的时候,更甚至是我们在web.config中这样设置之后<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>,会导致我们的中文cookie变成乱码,从而导致cookies无效,因此要将cookies转化成UTF-8的格式:代码如下:

    /// <summary>
    
/// 设置 Cookie
    
/// </summary>
    
/// <param name="lxfs"></param>
    
/// <param name="expiresDays"></param>

    public static void SetCookie(string key, string value, int expiresDays)
    
{
        DateTime expires 
= DateTime.Now.AddDays(expiresDays);
        HttpCookie MyCookie 
= new HttpCookie(key);
        MyCookie.Domain 
= ".yourdomain.com";
        MyCookie.Value 
= HttpUtility.UrlEncode(value);
        MyCookie.Expires 
= expires;
        HttpContext.Current.Response.Cookies.Add(MyCookie);
    }

读取cookie的时候使用这个函数:

 /// <summary>
    
/// 对cookie进行UTF编码
    
/// author:jake
    
/// bt:080414
    
/// </summary>
    
/// <param name="str"></param>
    
/// <returns></returns>

    public static string GetCookid(string str)
    
{
        Encoding stre 
= Encoding.GetEncoding("UTF-8");
        
return HttpUtility.UrlDecode(str,stre);
    }

如:

GetCookid(HttpContext.Current.Request.Cookies["sswoo_user"].Value)

如此以来即可解决中文字符cookie丢失的问题了!