Cookie chartset错误page_load ASP.NET

时间:2015-02-07 14:35:51

标签: asp.net vb.net cookies character-encoding pageload

我有土耳其语字符串“Sitemiziteğeniyormusunuz?”在Cookie中

我有一个网页。 Survey.aspx

 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Survey.aspx.vb" Inherits="Survey" Culture="tr-TR" UICulture="tr" %>

<!DOCTYPE html> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9" />
<html xmlns="http://www.w3.org/1999/xhtml" lang="tr">

<head runat="server"> 
<title></title> 
</head>
<body>
<form id="form1" runat="server">
<div> 
    <asp:Label ID="Label1" runat="server"></asp:Label>
 </div>
</form>
</body>
</html>

代码文件:Survey.aspx.vb

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim myCookie As HttpCookie = Request.Cookies("SurveyCookie")
    If myCookie IsNot Nothing Then
        Label1.Text = myCookie("Ask")
    End If
  End Sub

第一次加载此页面时没有任何问题

Label1的文字=“Sitemiziteğeniyormusunuz?”

但是当我加载第二次或更多时

Label1的文字=“Sitemizibe?eniyor musunuz?”

我已经设置了web.config

<system.web> 
<globalization requestEncoding="iso-8859-9" responseEncoding="iso-8859-9" culture="tr-TR" uiCulture="tr" fileEncoding="iso-8859-9" />
</system.web>

1 个答案:

答案 0 :(得分:0)

您应该在设置cookie之前对其进行URLEncode,并在检索时对URLDecode进行编码。这里有一个很好的描述cookie中允许的字符:Allowed characters in cookies