Passing a parameter through server.execute?

Can I pass a parameter through server.execute ?

Fx. I have an IF script in my site.asp where I need functions.asp?a=something&id=123 . Is it possible?!

On site.asp:

 dim id id = 123 if b = "hi" then server.execute("functions.asp?a=something&id=" & id) else response.write("No way dude") end if 

In functions.asp function

 a = request.querystring("a") id = request.querystring("id") if a = "something" and cint(id) > 100 then response.write("Yes way dude") else response.write("No way dude") end if 
+6
source share
4 answers

You cannot use querystring in Server.Execute , this is clearly stated in the official documentation .

What you can do much better: you can directly access the id variable defined in site.asp inside functions.asp , and you can also declare and set another variable a :

- site.asp:

 dim id, a id = 123 a = "something" server.execute("functions.asp") 

- functions.asp

 if a = "something" and cint(id) > 100 then response.write("Yes way dude") else response.write("No way dude") end if 

Strike>

Since it creates a completely new "scripting environment", the executable will not have access to the properties, methods or variables of the calling code, only to the global request parameters, session, etc.

Given this, I'm afraid the easiest way is to use the Session variable to pass the value between pages:

 Session("id") = 123 Session("a") = "something" 

And then:

 if Session("a") = "something" and Session("id") > 100 then response.write("Yes way dude") else response.write("No way dude") end if 
+5
source

This question may be old and resolved, but the best answer does not mention everything, and it has information published on Microsoft.com:


Server.Execute Method

The following collections and properties are available on the executed ASP page:

  • Application variables , even if installed on the calling page.
  • Session properties , even if they are set on the calling page.
  • Server variables and properties , even if they are set on the calling page.
  • Request collections and properties , even if they are set on the calling page. This includes Form and QueryString data passed to the calling page.
  • Collections of responses and properties . The executed .asp file can modify the HTTP headers. However, as with any .asp file, if the .asp executable tries to change the HTTP headers after sending the response to the client, it generates an error.

So, as you can see, there are five ways in which Microsoft suggests passing variables using the Server.Execute method. Before I saw this at Microsoft, the preferred method was Session , as the best answer suggests, as I saw this before the information on Microsoft.com. But having noticed that QueryStrings can be passed from the previous page, I would have to say this using Session to pass values. Session required if your application needs to add variables to the execution page.

But by passing variables, I would say QueryStrings , and this is easy to apply if your application allows flexibility. I'm sure you know how to use querystrings already, but in the sense of using it for the Server.Execute method Server.Execute you can simply do this:

Consider ASP1.asp and ASP2.asp :

ASP1.asp includes:

  Server.Execute("ASP2.asp") 

ASP2.asp includes:

  Response.Write Request("id") 

When you call ASP1.asp?id=123 you will notice that ASP2.asp also sees the same Querystring passed to ASP1.asp, so it would write 123 in ASP1.asp's response.

This is much less complicated than using Session for a task.

+3
source

In short: YES, you can use QueryString values ​​in conjunction with Server.Execute on an ASP.NET page or application.

You can pass dynamic variables in the QueryString argument compiled on an ASPX page (page1.aspx) as follows:

  Dim intExample1 As Int = 22 Dim strExample2 As String = "hello world" Server.Execute("page2.aspx?number=" & intExample1 & "&string=" & Server.UrlEncode(strExample2)) 

In this example, page2.aspx can reference and use the following values:

  Request.QueryString("number") Request.QueryString("string") 
0
source

Why not use #include instead of server.execute ?

I looked for the difference and found that in this particular case using #include is the best solution: https://en.wikibooks.org/wiki/Active_Server_Pages/Server-Side_Includes#What_it_Does

You need the variables defined on the parent page to be used on the child device, so your solution might be:

 dim id, a id = 123 a = "something" if b = "hi" then <!--#include file="functions.asp" --> else response.write("No way dude") end if 

In functions.asp function

 if a = "something" and cint(id) > 100 then response.write("Yes way dude") else response.write("No way dude") end if 

Benefits:

  • Just follow the steps on the same page.
  • Use delete variables instead of session variables.
  • Do not show internal variables in the main URL.
0
source

Source: https://habr.com/ru/post/902742/


All Articles