ASP 3.0 - 使用Server.Execute问题:患" ASP失忆" (文本修订版) [英] ASP 3.0 - Server.Execute Problems: Suffering from "ASP Amnesia" (Text Revised)

查看:190
本文介绍了ASP 3.0 - 使用Server.Execute问题:患" ASP失忆" (文本修订版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是IIS 6,并创建了两个ASP 3.0文件:
-Main.asp
-Colors.asp

I'm using IIS 6, and created Two ASP 3.0 files: -Main.asp -Colors.asp

<%
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'
%>

Col​​ors.asp

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

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

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

如果一个人要进入Colors.asp文件
以上并修改/添加它如下:

If one were to go into the Colors.asp file above and modify/append it to read as follows:

<%
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或sGreen这是在Colors.asp变暗了。有一次,她回来交给Main.asp她的无能。

One would receive a screen with "Color is Red" when sColor was true over at Main.asp and sString contained "Red." So I know she's getting over there, and also returning back over to Main.asp...but somehow she has no clue about those variables: sRed, sBlue, or sGreen that were dimmed over at Colors.asp. Once she gets back over to Main.asp she's clueless.

怎么办?为什么她有ASP失忆一次,她刚刚结束了在Colors.asp后得到回Main.asp?

What gives? Why does she have ASP Amnesia once she gets back to Main.asp after having just been over at Colors.asp?

修改

尊敬YougoTiger,

Dear YougoTiger,

我做你的建议(我认为)在Main.asp:

I did what you suggested (I think) in Main.asp:

If sColor = true then
   Server.Execute "Colors.asp"

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

没有...仍然有ASP Amnesia- SRED谁?

Nothing...still has ASP Amnesia- sRed Who?

编辑2

尊敬Bitwize,

我为了腾出服务器正在使用使用Server.Execute代替的#include。正如你所知道的#includes始终得到ASP首先处理,无论其是否是一个如果块内。基本上,我试图做动态服务器端通过使用Server.Execute的方式,这其实可以根据微软放在一个如果块中包括:

I'm using Server.Execute instead of #include in order to free up the server. As you know #includes always get handled first in ASP, regardless of whether they are inside an If block. I'm basically trying to do dynamic server-side includes by way of Server.Execute, which can in fact be placed within an If block according to Microsoft:

Microsoft支持 - 使用使用Server.Execute方法

新的ASP 3.0服务器的方法(注:这是最初 http://www.15seconds.com/issue/010220。 HTM 但该网站消失,链接现在是一个重定向到数字域。随意做自己的文章由保罗·利温搜索和更新这个链接,如果你能找到它。)

The New ASP 3.0 Server Methods (Note: this is was originally http://www.15seconds.com/issue/010220.htm but that site is gone, the link is now a redirect to a numeric domain. Feel free to do your own search for the article by Paul Litwin and update this link if you can find it.)

在ASP 3.0 神色

上的#includes 低下来

我还需要这方面的帮助,或者什么是在我的具体情况正在进行一个更好的解释。我已经得到了很多在Color.asp文件变暗变量的多,我不希望服务器费心如果sColor =假。

I still needing help with this, or a better explanation as to what is going on in my particular case. I've got a lot of dimmed variables over in that Color.asp file that I don't want the server to bother with if sColor=False.

推荐答案

别以为它可以在不改变一些工作要做。使用使用Server.Execute,2页完全不知道对方的局部变量(请参阅下面的证明)。一个包括会更好,虽然你失去了有条件的能力。

Don't think it can be done without some changes. Using server.execute, the 2 pages are completely unaware of each others local variables (see proof below). An include would be better although you do loose the conditional ability.

请求/响应对象由两个文件共享,因此您可以根据需要将这些工作。至于文件的发送变量只能选择会话或应用程序变量。请参阅以下code样本。

The Request / Response Objects are shared by both files so you can work with those as need be. As far as sending variables between the files your only option is session or application variables. See below for code sample.

文件1:

dim localParent
localParent="start Value"
Response.write("Parent:"&localParent&"<br>")
Server.Execute "file.asp"

Response.write("Parent after Exec:"&localParent&"<br>")

文件2:

Response.write("Child:"&localParent&"<br>")
localParent = "Child changed"
Response.write("Child Afer set:"&localParent&"<br>")

输出:

Parent:start Value
Child:
Child Afer set:Child changed
Parent after Exec:start Value

Session变量传递:
文件1:

Session variable passing: file 1:

Dim myVar
'Do stuff
session("myVar") = myVar ' Save variable in session
Server.Execute "file.asp"
myVar = session("myVar") 'get changed variable back out of session

文件2:

Dim myLocalVar
myLocalVar = session("myVar")   ' Get variable from session
'Do stuff to myLocalVar
session("myVar") = myLocalVar 'Put variable back into session for calling page to use.

这篇关于ASP 3.0 - 使用Server.Execute问题:患&QUOT; ASP失忆&QUOT; (文本修订版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆