[已解决问题]
解决于 2009-07-07 13:59
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">由于操作不当,关闭了自己的提问,没有能够补充问题解决途径,现在这里贴上,同时感谢<strong> </strong><a class="cnblogs_code" style="width: 81px; height: 29px;" href="http://www.cnblogs.com/winzheng/" target="_blank"><strong>winzheng</strong></a><strong> </strong>的关注,谢谢!</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">问题是由于Cookie传值乱码导致的,这里先把值转换成字节数组,再赋给Cookie,在用到Cookie时,再把Cookie值转换为字符串,这样就解决了乱码问题,以下是相关转换代码:</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><strong style="mso-bidi-font-weight: normal;"></strong></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">字符串与字节数组转换:</span></strong><a name="字符串与字节数组转换"></a><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 12pt;" lang="EN-US"></span></strong></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: #00b050; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;">(<span lang="EN-US">1</span>)字符串转换为字节数组<span lang="EN-US"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 11pt; color: #2b91af; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US">HttpCookie</span><span style="font-size: 11pt; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US"> cookie = <span style="color: blue;">new</span> <span style="color: #2b91af;">HttpCookie</span>(<span style="color: #a31515;">"UserName"</span>);</span><span style="font-size: 9pt;" lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: 11pt; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US">cookie.Value = <span style="color: #2b91af;">Convert</span>.ToBase64String(System.Text.<span style="color: #2b91af;">Encoding</span>.GetEncoding(<span style="color: #a31515;">"GB2312"</span>).GetBytes(reader[<span style="color: #a31515;">"name"</span>].ToString()));</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: 10pt; color: #00b050; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US">(2)</span><span style="font-size: 10pt; color: #00b050; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;">字节数组转换为字符串<span lang="EN-US"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: 11pt; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US">Session[<span style="color: #a31515;">"UserName"</span>] = System.Text.<span style="color: #2b91af;">Encoding</span>.GetEncoding(<span style="color: #a31515;">"GB2312"</span>).GetString(<span style="color: #2b91af;">Convert</span>.FromBase64String(Request.Cookies[<span style="color: #a31515;">"UserName"</span>].Value.ToString()));</span><span style="font-size: 10pt; color: #00b050; font-family: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes;" lang="EN-US"></span></p>