ASP亂碼確實棘手,這個說明比較權威。有待研究。哪的資料都不如官方資料權威。今天總算從MSDN中擇出了ASP編碼問題的解決方案。
... ASP亂碼確實棘手,這個說明比較權威。有待研究。
哪的資料都不如官方資料權威。今天總算從MSDN中擇出了ASP編碼問題的解決方案。
下面是MSDN中的一段話。 Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single response, and Session.CodePage affects dynamic strings in all responses in a session. |
這句話解釋清楚了@CODEPAGE,Response.CodePage,Session.CodePage 分別的作用是什么。
@CODEPAGE作用于所有靜態的字符串,比如某文件中的 const blogname="我的家"
Response.CodePage,Session.CodePage作用于所有動態輸出的字符串,比如<%=blogname%>
這句話很關鍵的是說明了Response.CodePage的作用范圍是a single response,而SXNA中聲明的Session.CodePage的作用范圍是all responses in a session。
再看另外一句話。 If Response.CodePage is not explicitly set in a page, it is implicitly set by Session.CodePage, if sessions are enabled. If sessions are not enabled, Response.CodePage is set by @CodePage, if @CodePage is present in the page. If there is no @CodePage in the page, Response.CodePage is set by the AspCodePage metabase property. If the AspCodePage metabase property is not set, or set to 0, Response.CodePage is set by the system ANSI code page. |
這句話我乍一看,把意思理解成了這樣:在sessions are enabled的時候,如果Response.CodePage沒有聲明,則Response.CodePage會被Session.CodePage賦值。如果sessions are not enabled的時候, 如果@CodePage已聲明,則Response.CodePage會被@CodePage賦值,等等.............
這句話解釋了為什么從SXNA中出來以后進入一些別的頁面比如oblog,z-blog等等容易出現亂碼,因為其他程序沒有聲明Response.CodePage而恰巧SXNA聲明了Session.CodePage,因此一進入SXNA,Session.CodePage立即被賦值(版本不同,有的版本賦了936有的版本賦了65001),而后進入其他程序的時候Response.CodePage馬上被Session.CodePage賦值,如果這時Response.CodePage與頁面本身編碼不一樣的話,頁面就會出現亂碼。所以進入z-blog出現亂碼的時候我查了當時的Session.CodePage和Response.CodePage都是936,而進入oblog出現亂碼的時候Session.CodePage和Response.CodePage都是65001.就是說要想保證葉面不出現亂碼,應該聲明Response.CodePage,否則他就會按照Session.CodePage來解釋網頁(而不是按照@codepage解釋網頁).
新聞熱點
疑難解答