Microsoft KB Archive/246915

= IIS: Using <% %> Tags Instead of  Tags Affects Processing Order =

Article ID: 246915

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q246915



We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:

http://www.microsoft.com/technet/security/prodtech/IIS.mspx



SYMPTOMS
When using  tags instead of or in addition to <% %> tags to denote Active Server Pages (ASP) code in a page, the processing of ASP code may appear to be out of order.



CAUSE
This behavior is by design. ASP code in  tags is processed after the end of the page's HTML information, whereas ASP code in <% %> tags is processed in-line.



MORE INFORMATION
The following examples will illustrate this behavior.   Save the following script as Test1.asp in a folder with at least "script" access defined:  Response.Write " Line 1 " Line 2 Browsing this page will output the following HTML: Line 2 Line 1 The HTML output would seem at first glance to be out of order based on the location of the script inside the page.   Save this next script as Test2.asp in the same folder as for the previous example: <% @language="vbscript" %> <%   Response.Write " Line 1 " %> Line 2 Browsing this page will output the following HTML: Line 1 Line 2 So, if you use  tags for ASP, they process after the page has processed, whereas <% %> tags execute in-line. This can lead to confusion, as shown in the following scenario.   Save this page as Test3.asp in the same folder as earlier: <script runat="server" language="vbscript"> strText = " Line 1 " <%   Response.Write strText %> Line 2 Browsing this page will output the following HTML: Line 2 The text "Line 1" is not output because the variable "strText" will not be populated until after the Response.Write has already been executed. </li></ul>

Keywords: kbprb kbpending KB246915

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.