Asp.net 网页的编码 - 可能的方式 - 差异 - web.config(全球化)与元标记与等
对 Asp.net 网页进行编码有哪些可能的方法?
下面链接中的 web.config(全球化)有什么区别:
和元标记,如下所示:
http://www.w3schools.com/tags/att_meta_http_equiv.asp
(我们也可以在 PAGE DIRECTIVE 中选择每个页面的编码,那么它和 有什么区别
http-equiv 属性?)
What are the possible ways to encode an Asp.net Web Page?
What is the difference between web.config (Globalization) in the link below:
How to: Select an Encoding for ASP.NET Web Page Globalization
And a meta tag like below:
http://www.w3schools.com/tags/att_meta_http_equiv.asp
(also we can select encoding on every page in PAGE DIRECTIVE, so what is the difference between that and the <meta>
http-equiv attribute?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 web.config 中设置的编码允许您配置页面发送时应采用的编码。
您在 Page 指令中设置的编码允许您覆盖各个页面的 web.config 设置(建议 - 不要使用它)。
您在 META 标记或响应标头中设置的编码(ASP .NET 将自动为您设置响应标头); 向浏览器提供有关页面发送的编码的有用提示,以便它可以正确解码。
换句话说,web.config、标头和元标记中的编码应设置为相同的编码才能正常工作。 UTF-8 是一个不错的选择 - 它可以处理大多数(至少是西欧)国际字符,并且每个字符都是单字节,除非该字符高于代码点 128(换句话说,英语文本在 UTF8 和 ASCII 中的大小相同) - 所以没有理由坚持使用 ASCII!)。
有关编码的必读文章的链接 - 如果您还没有阅读过,请阅读它。它会为你在未来节省一些悲伤。
The encoding you set in web.config allows you to configure the encoding that pages should be sent in.
The encoding you set in a Page directive allows you to override the web.config setting for individual pages (Word of advise - don't use it).
The encoding you set in the META tags or the response headers (ASP .NET will set response headers automagically for you); is a helpful hint to the browser about which encoding the page is sent in, so that it can decode it correctly.
In other words, the encoding in web.config, headers and in meta-tags should be set to the same encoding for things to work properly. UTF-8 is a good choice - it handles most (western european, at least) international chaaracters, and it is single byte per character unless the character is above codepoint 128 (in other words, english text is the same size in UTF8 and ASCII - so no excuse for sticking with ASCII !).
Link to the obligatory article about encodings - if you haven't yet, read it. It will save you some grief in the future.