Explore. Dream. Discover.

Samuel Chen's life

Twenty years from now you will be more disappointed by
the things that you didn't do than by the ones you did do.
So throw off the bowlines. Sail away from the safe harbor.
Catch the trade winds in your sails.

Explore. Dream. Discover.
—— Mark Twain

2004年4月26日 星期一

还是编码,最近老和编码打交道: 关于ASP页面 post 数据到ASP.NET页面的问题

在一个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) ?

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:Inherits="AspPostToAsp.Net.WebForm1" codePage="1252"%>
...

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

标签: ,

2004年4月25日 星期日

ASP.NET中的Static变量

今天在看到禁止在页面中使用static变量一文及其评论中关于对ASP.NET中static变量的探讨,觉得并没有涉及static的实质 — 什么是static。

ASP.NET和C++中的static并没有多少不同,实质上他们都是在编译期就已存在的地址空间。换句话说,在你Build成功之后,项目的DLL文件中已经存在了这个static变量(或者类)的空间,亦即在你运行时系统载入DLL后这个变量/类的所谓实例已经存在,而且是应用程序所公用,所以你才可以直接使用,同时所有的页面用的都是同一块空间

普通的类你需要new一个instance才可以使用,原因就在于应用程序中间只有声明而没有定义,new的时候就在堆里划分一块空间给他的一个实例。

一个简单的实验,大家就很容易的明白他们之间的区别:新建个简单的project,添加一个类,类增加一个变量,编译,记录dll文件的大小;然后把变量变成static的(当然你的class也必须成为static的了,想想这是为什么),编译,记录dll文件大小;比较两个dll大小,是不是后面一个比前面大呢?:)

标签: ,