When some users of my ASP.NET app enter the following text
当我的ASP.NET应用程序的某些用户输入以下文本时
Je bénéficie d’un coaching
Jebénéficied'un教练
I get the following value in my Request.Form:
我在Request.Form中获得以下值:
Je b�n�ficie d�un coaching
Jeb n ficied un教练
At first my page had the encoding set to Latin1, and I thought that changing it to Unicode (UTF8) using the following meta tag would help:
起初我的页面的编码设置为Latin1,我认为使用以下元标记将其更改为Unicode(UTF8)会有所帮助:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
But after the change I still get those "blocks" in Request.Form.
但是在改变之后我仍然在Request.Form中得到那些“块”。
Now the weird thing is, this happens when I submit the page which is being served by IIS (e.g http://localhost/myform.aspx). If I get the same html, save it locally, open the file in the browser directly (e.g. c:\myform.html) and submit it, all is fine, I see the unicode characters in my Request.Form as they should be.
现在奇怪的是,当我提交由IIS提供的页面时会发生这种情况(例如http://localhost/myform.aspx)。如果我得到相同的html,在本地保存,直接在浏览器中打开文件(例如c:\ myform.html)并提交它,一切都很好,我看到我的Request.Form中的unicode字符应该是。
Any tips? I am lost here...
有小费吗?我迷失在这里......
2 个解决方案
#1
The meta tag you mentioned ensures that the content of the page is rendered following the UTF-8 codepage, but doesn't inform how data posted should be handled. For that, you should add this attribute in your form tag:
您提到的元标记可确保页面内容在UTF-8代码页之后呈现,但不会告知应如何处理发布的数据。为此,您应该在表单标记中添加此属性:
<form accept-charset="utf-8" ....>
No idea why the behaviour is different when you run it through IIS and the file system, though.
但是,当您通过IIS和文件系统运行时,不知道为什么行为会有所不同。
#2
You can try "charset=ISO-8859-1". I hope that help's.
您可以尝试“charset = ISO-8859-1”。我希望有帮助。
#1
The meta tag you mentioned ensures that the content of the page is rendered following the UTF-8 codepage, but doesn't inform how data posted should be handled. For that, you should add this attribute in your form tag:
您提到的元标记可确保页面内容在UTF-8代码页之后呈现,但不会告知应如何处理发布的数据。为此,您应该在表单标记中添加此属性:
<form accept-charset="utf-8" ....>
No idea why the behaviour is different when you run it through IIS and the file system, though.
但是,当您通过IIS和文件系统运行时,不知道为什么行为会有所不同。
#2
You can try "charset=ISO-8859-1". I hope that help's.
您可以尝试“charset = ISO-8859-1”。我希望有帮助。