特定のページだけ文字コードが違う!文字化け回避
ASP.netでWEBアプリーケーションを開発していて、
あるページへ他のサイトからデータがpostされてくる場合
UTF-8で送られてくるとは限りません。
ところがサイト全体はすでにUTF-8で出来上がっている。
さてどうしましょう?
ということは良くあります。
この場合受け取ったデータを表示したりデータベースへ
収納するにも、文字化けに苦しみます。
大概の方はエンコード・デコードを組み合わせて
コードを変換しようとか、
ページに入る前のpostされたデータを加工しようと
考えますがそんな複雑な工程は不要です。
最も簡単に対処する方法はこれです。
web.config内に
<location path="受け側のページ名.aspx">
<!-- この例では携帯電話からのポストをShift_JISで受けている -->
<system.web>
<globalization fileEncoding="Shift_JIS" requestEncoding="Shift_JIS" responseEncoding="Shift_JIS"
/>
</system.web>
</location>
受け側のページ名.aspx内では
Dim 変数名 As String
変数名 = Server.HtmlDecode(Request.Form("変数名"))
で受信しています。
これで文字化けは回避できます。
対応バージョン:2.0
1.1は動作確認していません。
記事id:58 / 4038PV
関連記事
Warning: simplexml_load_file() [
function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in
/home/session-2/www/02_zatu/system_files/core_sys.php on line
41
Warning: simplexml_load_file(http://www.jigen.xyz/index.xml) [
function.simplexml-load-file]: failed to open stream: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in
/home/session-2/www/02_zatu/system_files/core_sys.php on line
41
Warning: simplexml_load_file() [
function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.jigen.xyz/index.xml" in
/home/session-2/www/02_zatu/system_files/core_sys.php on line
41
Warning: Invalid argument supplied for foreach() in
/home/session-2/www/02_zatu/system_files/core_sys.php on line
42