還是編碼,最近老和編碼打交道-_-: 關於ASP頁面 post 資料到ASP.NET頁面的問題

來源:互聯網
上載者:User
從asp頁面到asp.net頁面post資料,編碼會有什麼影響?
在一個bbs上和人聊到了這個東西,雖然很簡單,但我覺得應該還是有很多人沒有注意到的問題,就貼出來參考一下,在HTML頁面上post應該也是這樣的。

Yovav
 : do U think it's possible that codepage is "lost" when POSTing data from ASP to an ASP.NET page ?

Samuel:  To your question "do U think it's possible that codepage is "lost" when POSTing data from ASP to an ASP.NET page ? ", I think it's not possible ---
It's really truth .

  When posting data from ASP to ASP.NET page, the codepage will automatically be changed into UTF-8.

  Therefor, you'd better set your ASP.NET page's codepage/charset correctly.

Yovav : How can I traslate this to ASP.NET (or at least define the CodePage) ?

<%@CODEPAGE="1252"%>

<%
Session.CodePage=1252 ' IMPORTANT: syncronize with the server code page
Response.Charset= "utf-8" ' IMPORTANT: make the server respond with correct charset
%>

Thanks again.
My form is now POSTing correctly - thanks to you

Samuel: From your code, I found that you want dynamic codepage/charset for response. Is it?

For dynamic response in ASP.NET, put the follow code in Page_Load() event of .cs/.vb file :

Session.CodePage=1252
Response.Charset="utf-8";

For static response, modify .aspx file like this:

<%@ Page language="c#" Codebehind="AspNetPage1.aspx.cs" AutoEventWireup="false" 
Inherits="AspPostToAsp.Net.WebForm1" codePage="1252"%>
...
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

If you used Session and Response Object to set codepage/charset, the defined value in .aspx file will be invalid.

It seems that codepage of UTF-8 is 65001 against 1252 in ASP.NET.

Yovav : I thought I should do it like this,

so the only solution for me is to use your great two conversion functions

great job ! - I'm sure that a lot of people don't have a clue how to deal with this problem...

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.