SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    config.asp file to declare variables for include files

    let me just start that I am an asp newb...

    searched all over the internet for this answer and can't seem to find anything

    I have a config.asp file (located on my server (ip_address/root/config.asp) that i am declaring a variable in:

    Code:
    <&#37; 
    dim root_path 
    root_path = "/rootfolder/"
     %>
    I want to include this file in a subfolder "http://ip_address/root/subfolder/"

    a) is this the only way to include the config file in it? <!--#include virtual="/root/config.asp"-->
    -b/c if that is the case, I would have to delete the /root out when i move from dev to prod (seems pointless)

    b) can I include a declared variable in an include statement?
    Code:
    <!--#include virtual="<%=root_path%>inc/header.asp"-->
    i get an asp error in this case...

    Active Server Pages error 'ASP 0126'

    Include file not found

    /root/subfolder/default.asp, line 34

    The include file '<%=root_path%>inc/header.asp' was not found.


    If anyone can provide help, I would be very appreciative! I have scoured the internet for the past 2 business days looking for help...

  2. #2
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    358
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Include files are merged into the page code base before any asp code starts running, so you can't make a dynamic path like you're trying to do. From IIS 5+ server.execute and/or server.transfer may offer a solution for you.
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why not use relative file paths?

    Code:
    <!-- #include file="../inc/header.asp" -->
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    Why not use relative file paths?

    Code:
    <!-- #include file="../inc/header.asp" -->
    That ^ results in this error:
    Active Server Pages error 'ASP 0131'

    Disallowed Parent Path

    /root/subfolder/default.asp, line 34

    The Include file '../inc/header.asp' cannot contain '..' to indicate the parent directory.


    It will not let me do:
    Code:
    <!-- #include file="/inc/header.asp" -->
    I get this error if so:
    Active Server Pages error 'ASP 0130'

    Invalid File attribute

    /root/subfolder/default.asp, line 34

    File attribute '/inc/header.asp' cannot start with forward slash or back slash.


    And I cannot do:
    Code:
    <!-- #include file="inc/header.asp" -->
    b/c the file is not located at subfolder/inc, it is located at root/inc

  5. #5
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Doug G View Post
    Include files are merged into the page code base before any asp code starts running, so you can't make a dynamic path like you're trying to do. From IIS 5+ server.execute and/or server.transfer may offer a solution for you.
    Thanks Doug, I will look and see if those solutions work!

  6. #6
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simply deleting the /root out when you move from dev to prod doesn't seem like a big deal .....

  7. #7
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    simply deleting the /root out when you move from dev to prod doesn't seem like a big deal .....
    agreed, if it were only on one page, but we are using this page as a template to duplicate over 100 subfolders...

  8. #8
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two ways to include files in ASP. With the "include file" or "include virtual" options.

    your choice.

  9. #9
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    There are two ways to include files in ASP. With the "include file" or "include virtual" options.

    your choice.
    Thanks, I am looking into the server.execute option that was suggested above, do you see that this could be potential solution?

  10. #10
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Server.Execute drawbacks are discussed here:


    http://docs.sun.com/source/817-2514-...uiltIn142.html

  11. #11
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    358
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    Server.Execute drawbacks are discussed here:


    http://docs.sun.com/source/817-2514-...uiltIn142.html
    The comments in that page may or may not be valid for IIS hosted asp sites, they are written for Sun One, which is an asp emulation designed to run on unix-like servers.
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  12. #12
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Doug G View Post
    The comments in that page may or may not be valid for IIS hosted asp sites, they are written for Sun One, which is an asp emulation designed to run on unix-like servers.
    It's still valid - here's another link if it helps.

    http://www.15seconds.com/issue/010220.htm

  13. #13
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I might make absolutely no sense here but I am going to ask it anyways:

    Can I use a global.asa file with code like this:

    Code:
    <script language="vbscript" runat="server">
    
    sub Application_OnStart
    Application("Environment")="http://ip_address/root"
    end sub
    
    </script>
    And use a server.execute in an asp file to call my application object?

    Is this possible? I am going to guess no as I cannot find my answer by searching...but I figured I'd ask here as I may not be using the right search terms.

    Thanks!

  14. #14
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried it ? Did it work ?

    I doubt it will work.

    If you're going to use Server.Execute anyway, why not use it as intended ?

  15. #15
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Ok, you've covered a lot of ground since you started this topic and it's splintered all over the place. I think I'll tackle include files first.

    Include files - I always (out of habit) use relative paths (<!-- #include file="../inc/header.asp" -->) for my includes because it has been my experience that it makes my work more portable. I often use include files for global variables, paths, bolierplate code, object declarations etc....

    Servers from Win2003 and up will throw a parent path disallowed error unless you go into your server control panel and allow it under one of the advanced menus. I haven't had to do that for a while but it's just a checkbox that needs to be selected and then reboot the server.

    Server.Execute - This might be off topic but server.execute as become a very good friend of mine because it provides the ability to include and execute code according to the status of the program being executed as if it were part of the script that calls it. It's well worth the effort to learn if your going to do ASP classic coding for any period of time.

    webber123456 included a great link to the 15 second site so give that a read. It explains server.execute quite nicely.

    A common situation that I use server.execute is to include forms or display code in web admin sections. I can have a conditional statement that asks whether we're in edit or preview and depending on the answer I can set my action_variable = edit-form.asp or action_variable = preview.asp. Then in the body of the page I have Server.Execute(action_variable). All of the variable included in my action_variable regardless of whether it is a form or preview page are executed according to the code that preceded it.

    I think the drawback to server.execute is that you can't server.execute some massive ASP library and pick the part that you want to use to suite the circumstances of your code. Instead, I just have small blocks of code that I use server.execute with and it really is a helpful way to keep complex ASP applications from becoming a maintenance nightmare.

    Global ASA - Hopefully you can get your include working with relative (parent) paths and you don't need a global.asa but if I read your first post correctly global.asa does what you are trying to use your custom page config.asp.

    You have two sections of the code to deal with the application and the session, so you would have to figure out whether the code your dealing with is for the application or the visitors session and apply your code accordingly. I have a hunch that you would be applying your code to the application but I could be wrong.

    I stay away from global.asa myself because I in the past ran into troubles not understanding how it worked but if you need to assign global variable, objects, etc... then global.asa might be what you're looking for. There are some decent (old) ASP books that cover global.asa but this link might shed some light for you.

    Here's another link

    Good luck!

    Andrew
    Last edited by awasson; Oct 24, 2010 at 15:06. Reason: clarification...
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  16. #16
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thank you for the detail explanations! at this moment i am trying to persuade our server group to enable parent paths...so hopefully they will and this will be an easier solution than trying any of the suggested ones i've already wasted a lot of time trying to work around this...

  17. #17
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by surina777 View Post
    wow thank you for the detail explanations! at this moment i am trying to persuade our server group to enable parent paths...so hopefully they will and this will be an easier solution than trying any of the suggested ones i've already wasted a lot of time trying to work around this...
    No worries and yes, enabling parent paths is the best (easiest) way around the issue.

    It's really easy to do once you know where it is in the server control snap-in. It's been a few years since I had to do it on my own servers so I don't recall the exact steps, otherwise I would have provided some more detail.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  18. #18
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    It's still valid - here's another link if it helps.

    http://www.15seconds.com/issue/010220.htm
    Visit the below link for more info on Server.Execute method:
    http://www.bigresource.com/ASP-Serve...-q56dmupM.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •