ASP 3.0 - Server.Execute问题:患有“ASP失忆症”

时间:2011-02-14 20:56:34

标签: asp-classic

创建了两个ASP 3.0文件: -Main.asp -Colors.asp


Main.asp

<%

Blah Blah Blah...

If sColor = true then
Server.Execute "Colors.asp"
End If
'If sColor is true, Pops over to Colors.asp
'Then pops right back over to here again

'Once back here again, it has no idea what
'sRed or sBlue was at all...it's as if has
'been "blank slated"...sRed? Who the heck is sRed?

If sRed then
Response.Write "Color is Red"
End If
'Does not work...skips right over...
'Who is sRed? What is sRed?
'Oh well, keep on truckin'

%&gt;


Colors.asp

<%
Dim sRed
sRed = instr(sString, "Red") >0

Dim sBlue
sBlue = instr(sString, "Blue") >0

Dim sGreen
sGreen = instr(sString, "Green") >0

%&gt;


如果要进入Colors.asp文件 上面并修改/附加它如下:

<%
Dim sRed
sRed = instr(sString, "Red") >0

Dim sBlue
sBlue = instr(sString, "Blue") >0

Dim sGreen
sGreen = instr(sString, "Green") >0

If sRed then
Response.Write "Color is Red"
End If

%>

有人会收到“颜色为红色”的屏幕 当sColor在Main.asp和sString上为真时 包含“红色”。所以我知道她到了那里, 并且还回到Main.asp ...但不知何故 她对这些变量一无所知:sRed,sBlue, 或者是在Colors.asp上变暗的sGreen。一旦她 回到Main.asp,她一无所知。

是什么给出的?为什么她一旦得到ASP Amnesia 刚刚在Colors.asp上结束后回到Main.asp?

顺便说一下,我曾经有一个女朋友的行为方式相同。 那么什么样的ASP hanky panky在Colors.asp上过来了?

请帮忙!

ASP Pee-Wee

3 个答案:

答案 0 :(得分:1)

执行的页面无法访问调用页面中的局部变量,反之,调用页面也无法访问已执行页面中的局部变量。无论你是否声明它们都没有区别,两个脚本没有在同一个上下文中执行,更不用说相同的范围了。

有效地调用Server.Execute()会导致执行的页面被隔离执行,并且在调用它的时候将其输出合并到调用页面的输出中:

  

IIS处理.asp文件后   在输入参数中指定   Server.Execute,响应是   返回到调用的ASP脚本。

     

以下收藏品和   属性可用于   执行ASP页面:

* Application variables, even if they are set in the calling page.
* Session properties, even if they are set in the calling page.
* Server variables and properties, even if they are set in the calling page.
* Request collections and properties, even if they are set in the calling page. This includes Form and QueryString data passed to the calling page.
* Response collections and properties. The executed .asp file may modify HTTP headers. However, as with any .asp file, if the executed .asp file attempts to modify HTTP headers after it sends a response to the client, it generates an error.
     

如果调用中包含文件   页面使用#include,执行   .asp不会使用它。例如,你   可能在文件中有一个子程序   包含在您的呼叫页面中,但是   执行的.asp无法识别   子程序名称。你必须包括   每个执行.asp中的文件   需要子程序。

如果要在脚本之间进行变量传递,最好使用include指令。如果你必须进行变量传递,那么你将不得不使用ApplicationSession对象进行评审,我不会建议。

答案 1 :(得分:0)

文档(http://msdn.microsoft.com/en-us/library/ms525849(v=vs.90).aspx)说:

  

Execute方法调用.asp文件,   并将其处理为好像是它的一部分   调用ASP脚本。执行   方法类似于过程调用   在许多编程语言中。

如果它类似于过程调用,我想对变量进行范围调整也是有意义的。正如Dee所说,在调用页面中声明变量,它应该可以工作。

答案 2 :(得分:-1)

您可能需要调整调用页面中的变量(?)