An in-depth study of ASP coding problems and final solutions _ Application techniques

Source: Internet
Author: User

ASP garbled is really tricky, this description is more authoritative. remains to be studied. No information is as authoritative as official information. Today, we've finally chosen the solution for ASP coding problems from MSDN.
... ASP garbled is really tricky, this description is more authoritative. remains to be studied.

No information is as authoritative as official information. Today, we've finally chosen the solution for ASP coding problems from MSDN.

The following is a passage from MSDN.

Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single Response, and session.codepage affects dy Namic strings in all responses.

This sentence explains clearly @CODEPAGE, what is the role ofresponse.codepage,session.codepage respectively.

@CODEPAGE Action on all static strings, such as the const blogname= in a file "my home"

response.codepage,session.codepage A string that acts on all dynamic outputs, such as <%=blogname%>

The key point of this statement is that the scope of the response.codepage is a single Response, and the Session.CodePage declared in Sxna is scoped to all Responses in a session.

Look at another word.

If response.codepage is isn't explicitly set in a page, it's implicitly set by Session.CodePage, if SE Ssions are enabled. If sessions are not enabled, response.codepage are set by @CodePage, if @CodePage was present in The page. If there is no @CodePage in the page, Response.CodePage are set by the AspCodePage metabase property. If the AspCodePage metabase property isn't set, or set to 0, response.codepage be set by the system ANSI code Page.

At first glance, I understood the meaning as follows: When sessions are enabled, if Response.CodePage did not declare, Response.CodePage would be assigned a value by Session.CodePage. If the sessions are not enabled, if @codepage has been declared, Response.CodePage will be @codepage assigned, and so on ...

This sentence explains why after coming out of the sxna into some other pages such as Oblog,z-blog and so on easily garbled, Because other programs do not declare response.codepage and happen to Sxna declare Session.CodePage, as soon as one enters the Sxna,session.codepage is assigned (the version is different, some version has 936 of the version of 65001), And then enter the other program when Response.CodePage immediately be Session.CodePage assignment , if the Response.CodePage and the page itself encoding is not the same , the page will appear garbled. So into the z-blog appear garbled when I checked the Session.CodePage and Response.CodePage are 936, and into the Oblog appear garbled when Session.CodePage and Response.CodePage are 65001. is said to ensure that the leaf does not appear garbled, should declare response.codepage, otherwise he will be according to Session.CodePage to explain the page (rather than according to @codepage explain the page).

If just according to the above explanation, I am actually very confused, because we are using the Chinese system, when every time you enter the browser you can try to output session.codepage, you can see that he is 936! Why did he not assign the default Session.CodePage 936 to Response.CodePage when entering Z-blog? Instead of giving @codepage to Response.CodePage? Under what circumstances will session.codepage assign value to Response.CodePage? The original sessions are enabled how to understand it?

Perhaps the above words should be understood in this way:

When Session.CodePage is declared by any program, if Response.CodePage is not declared, then Response.CodePage is Session.CodePage assigned. If the Session.CodePage is not declared by any program, if the @codepage has been declared, then Response.CodePage will be @codepage assigned, ..., The final page dynamic content is explained by the value of Response.CodePage.

Because Zblog and Oblog both declared the @codepage, the user just started the machine and then went into the browser to browse Zblog and Oblog Response.CodePage were assigned the @codepage, so the foliage showed normal.

This statement further explains the reason for the garbled

If you set response.codepage or session.codepage explicitly, does so before sending non-literal to The client. If use literal and non-literal strings the same page, make sure the code page of @CODEPAGE matches the Cod E page of Response.CodePage, or the literal strings are encoded differently from the non-literal strings and disp Lay incorrectly.

One of the more useful words is that if response.codepage and @CODEPAGE not the same word will produce garbled. That is to say, when the Z-blog @CODEPAGE=65001 and Z-blog response.codepage is Session.CodePage assigned to 936 when will appear garbled, Oblog and vice versa.

I don't know, that's a lot of explanations, no-_-| |

Let's explain why Sxna sometimes assigns session.codepage to 936, and I have a version that says:

<% Originalcodepage=session.codepage%>

.......

<% Session.codepage=originalcodepage%>

When the user enters the browser session.codepage defaults to 936, this time the default 936 is not a program declaration, so will not be assigned to Response.CodePage, when entering the Sxna, Session.CodePage by the above code a toss into the program statement session.codepage=936, so then enter the Zblog when the 936 gave Response.CodePage.

So far, the whole reason has been analyzed clearly.

Therefore, to ensure that the ASP leaf must not appear garbled code should be such: (assuming that the UTF-8 leaves)

<%@ codepage=65001%>

<% response.codepage=65001%>

<% response.charset= "UTF-8"%>

Further explain why to add Response.Charset, because MSDN said should add ... Oh

If The code page is set in a page, then Response.Charset should also to be set.

In addition, the file should be encoded in the same format as @codepage:

The file format of a Web page must is the same as the @CODEPAGE used in the page.

This is why Zblog,pjblog and other programs want to save the file into a UTF8 encoding format.

In summary, if all the procedures are declared Response.CodePage will not be session.codepage interference and garbled. So Session.CodePage is still not easy to use!

Reference articles:

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/268f1db1-9a36-4591-956b-d7269aeadcb0.asp

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/582e6f47-52eb-413e-8b5d-c99145cb61d8.asp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.