context.Response.Charset = Encoding.UTF8.ToString();

橙三吉。 提交于 2019-12-30 04:48:09

问题


I had used this in my code to set the Charset but IE did not like it. Any reason why?

context.Response.Charset = Encoding.UTF8.ToString();

I ended up having to set it to just context.Response.ContentType = "application/json;charset=utf-8" or context.Response.Charset = "utf-8"; instead. Not sure then what Encoding.UTF8.ToString(); would be utilized for if IE can't take it


回答1:


Context.Response.Charset = Encoding.UTF8.WebName;

Gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.




回答2:


Encoding.UTF8.ToString();

doesn't return

"utf-8"

It returns

"System.Text.UTF8Encoding"

which is the name of the type that Encoding.UTF8 lives in.

The name of the type (or class definition) is always returned by Object.ToString() if there is no overriding method in the class (which is the case here).




回答3:


use Encoding.UTF8.WebName to get the value to be used in the charset.



来源:https://stackoverflow.com/questions/1096125/context-response-charset-encoding-utf8-tostring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!