Passing a parameter through server.execute?

后端 未结 4 758
南笙
南笙 2021-01-12 09:34

It is possible to pass a parameter through server.execute?

Fx. I have in my site.asp an IF-scenario where I need functions.asp?a=some

4条回答
  •  走了就别回头了
    2021-01-12 09:53

    This question may be old and resolved, but the best answer doesn't mention everything, and there is information clearly posted on Microsoft.com about it:


    Server.Execute Method

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

    1. Application variables, even if they are set in the calling page.
    2. Session properties, even if they are set in the calling page.
    3. Server variables and properties, even if they are set in the calling page.
    4. Request collections and properties, even if they are set in the calling page. This includes Form and QueryString data passed to the calling page.
    5. 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.

    So as you can see, there are 5 ways Microsoft suggests to pass variables through to a Server.Execute method. Before I saw this on Microsoft, the preferred method was Session, as the best answer suggests, since I saw this before the info on Microsoft.com. But after noticing that QueryStrings can be passed from the previous page, I would have to say this beats using Session for passing values. Session would be needed if your application required you adding variables to the executing page.

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

    Consider having 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 see's the same Querystring passed to ASP1.asp, so it would write 123 on the response of ASP1.asp.

    That's much less complicated than using a Session for the task.

提交回复
热议问题