zoukankan      html  css  js  c++  java
  • 还是编码,最近老和编码打交道_: 关于ASP页面 post 数据到ASP.NET页面的问题

    从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...




  • 相关阅读:
    eclipse打包
    java reflect 小例子
    linux查看java jdk安装路径和设置环境变量
    mapreduce (一) 物理图解+逻辑图解
    java url 解码 编码 奇怪的解码两次
    cygwin+hadoop+eclipse (三) 运行wordcount实例
    nutch 与 solr 的结合
    一个项目可以有多个源代码路径
    SHAppBarMessage
    记录系统开机启动登录注销等信息
  • 原文地址:https://www.cnblogs.com/Samuel/p/7752.html
Copyright © 2011-2022 走看看