Server.MapPath returning wrong path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Rebbeck

    #1

    Server.MapPath returning wrong path

    I've got the directory f:\Company\Prod uct set as web shared so it's got a
    virtual directory in the default web site on my test server's IIS. If I try
    to use Server.MapPath in that site it returns a path within
    c:\Inetpub\wwwr oot rather than the real path.

    Can anyone please tell me why this isn't working?

    Regards,
    John


  • Aaron Bertrand [MVP]

    #2
    Re: Server.MapPath returning wrong path

    Server.MapPath uses the root of the default web site as its determination of
    the local folder. It doesn't actually look at individual virtual
    directories, for some bizarre reason... I think it's a bug.




    "John Rebbeck" <john@rebent.co m> wrote in message
    news:OnrDKoEfDH A.3164@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I've got the directory f:\Company\Prod uct set as web shared so it's got a
    > virtual directory in the default web site on my test server's IIS. If I[/color]
    try[color=blue]
    > to use Server.MapPath in that site it returns a path within
    > c:\Inetpub\wwwr oot rather than the real path.
    >
    > Can anyone please tell me why this isn't working?
    >
    > Regards,
    > John
    >
    >[/color]


    Comment

    • John Rebbeck

      #3
      Re: Server.MapPath returning wrong path

      Any way to get around it?

      "Aaron Bertrand [MVP]" <aaron@TRASHasp faq.com> wrote in message
      news:eWKhq5EfDH A.3268@tk2msftn gp13.phx.gbl...[color=blue]
      > Server.MapPath uses the root of the default web site as its determination[/color]
      of[color=blue]
      > the local folder. It doesn't actually look at individual virtual
      > directories, for some bizarre reason... I think it's a bug.
      >
      >
      >
      >
      > "John Rebbeck" <john@rebent.co m> wrote in message
      > news:OnrDKoEfDH A.3164@TK2MSFTN GP11.phx.gbl...[color=green]
      > > I've got the directory f:\Company\Prod uct set as web shared so it's got[/color][/color]
      a[color=blue][color=green]
      > > virtual directory in the default web site on my test server's IIS. If I[/color]
      > try[color=green]
      > > to use Server.MapPath in that site it returns a path within
      > > c:\Inetpub\wwwr oot rather than the real path.
      > >
      > > Can anyone please tell me why this isn't working?
      > >
      > > Regards,
      > > John
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Phillip Windell

        #4
        Re: Server.MapPath returning wrong path

        I'm not sure but what does using the Server Variable
        APPL_PHYSICAL_P ATH produce?

        I think the syntax would be:
        Response.Write Request.ServerV ariables("APPL_ PHYSICAL_PATH ")
        Be double check that to be sure.


        --

        Phillip Windell [CCNA, MVP, MCP]
        pwindell@wandtv .com
        WAND-TV (ABC Affiliate)


        "John Rebbeck" <john@rebent.co m> wrote in message
        news:#N0b8VLfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Any way to get around it?
        >
        > "Aaron Bertrand [MVP]" <aaron@TRASHasp faq.com> wrote in message
        > news:eWKhq5EfDH A.3268@tk2msftn gp13.phx.gbl...[color=green]
        > > Server.MapPath uses the root of the default web site as its[/color][/color]
        determination[color=blue]
        > of[color=green]
        > > the local folder. It doesn't actually look at individual virtual
        > > directories, for some bizarre reason... I think it's a bug.
        > >
        > >
        > >
        > >
        > > "John Rebbeck" <john@rebent.co m> wrote in message
        > > news:OnrDKoEfDH A.3164@TK2MSFTN GP11.phx.gbl...[color=darkred]
        > > > I've got the directory f:\Company\Prod uct set as web shared so[/color][/color][/color]
        it's got[color=blue]
        > a[color=green][color=darkred]
        > > > virtual directory in the default web site on my test server's[/color][/color][/color]
        IIS. If I[color=blue][color=green]
        > > try[color=darkred]
        > > > to use Server.MapPath in that site it returns a path within
        > > > c:\Inetpub\wwwr oot rather than the real path.
        > > >
        > > > Can anyone please tell me why this isn't working?
        > > >
        > > > Regards,
        > > > John
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Mark Schupp

          #5
          Re: Server.MapPath returning wrong path

          > > "Aaron Bertrand [MVP]" <aaron@TRASHasp faq.com> wrote in message[color=blue][color=green]
          > > news:eWKhq5EfDH A.3268@tk2msftn gp13.phx.gbl...[color=darkred]
          > > > Server.MapPath uses the root of the default web site as its[/color][/color]
          > determination[color=green]
          > > of[color=darkred]
          > > > the local folder. It doesn't actually look at individual virtual
          > > > directories, for some bizarre reason... I think it's a bug.
          > > >
          > > >
          > > >
          > > >
          > > > "John Rebbeck" <john@rebent.co m> wrote in message
          > > > news:OnrDKoEfDH A.3164@TK2MSFTN GP11.phx.gbl...
          > > > > I've got the directory f:\Company\Prod uct set as web shared so[/color][/color]
          > it's got[color=green]
          > > a[color=darkred]
          > > > > virtual directory in the default web site on my test server's[/color][/color]
          > IIS. If I[color=green][color=darkred]
          > > > try
          > > > > to use Server.MapPath in that site it returns a path within
          > > > > c:\Inetpub\wwwr oot rather than the real path.
          > > > >
          > > > > Can anyone please tell me why this isn't working?
          > > > >
          > > > > Regards,
          > > > > John
          > > > >[/color][/color][/color]

          I can't duplicate this behavior. MapPath always returns the correct path for
          me. Maybe John could post his code and physical directory structure?

          --
          Mark Schupp
          --
          Head of Development
          Integrity eLearning
          Online Learning Solutions Provider
          mschupp@ielearn ing.com
          Advancing limitless knowledge and continual growth to create confident problem solvers, one course at a time.

          714.637.9480 x17




          Comment

          • Phillip Windell

            #6
            Re: Server.MapPath returning wrong path

            "Mark Schupp" <mschupp@ielear ning.com> wrote in message
            news:evJMvaXfDH A.3700@TK2MSFTN GP11.phx.gbl...[color=blue]
            > I can't duplicate this behavior. MapPath always returns the correct[/color]
            path for[color=blue]
            > me. Maybe John could post his code and physical directory structure?[/color]

            I've had it do that same to me. If you run a site from a Virtual
            Folder instead of an actual Site the MapPath would use the parrent
            Site as the starting point instead of the Virtual Directory root. This
            is what you would run into with, say, Win2000 Pro where the IIS is
            limited to one site, so each separate website runs from its own
            Virtual Directory.

            I got around it by just switching the Home Directory of the only Site
            to what ever I needed at the moment....it is only a developement
            machine so that works fine for me.

            --

            Phillip Windell [CCNA, MVP, MCP]
            pwindell@wandtv .com
            WAND-TV (ABC Affiliate)



            Comment

            • Mark Schupp

              #7
              Re: Server.MapPath returning wrong path

              "Phillip Windell" <pwindell@wandt v.com> wrote in message
              news:%23rK8Mmff DHA.128@tk2msft ngp13.phx.gbl.. .
              ....[color=blue]
              > I've had it do that same to me. If you run a site from a Virtual
              > Folder instead of an actual Site the MapPath would use the parrent
              > Site as the starting point instead of the Virtual Directory root. This
              > is what you would run into with, say, Win2000 Pro where the IIS is
              > limited to one site, so each separate website runs from its own
              > Virtual Directory.[/color]

              Still not clear on what you mean by each separate "website" running in its
              own virtual directory when you can only have a single web site on the
              system. Do you mean that there is a way to make it look like there are
              multiple sites on the system? What would the URLs to 2 separate "websites"
              look like?

              --
              Mark Schupp
              --
              Head of Development
              Integrity eLearning
              Online Learning Solutions Provider
              mschupp@ielearn ing.com
              Advancing limitless knowledge and continual growth to create confident problem solvers, one course at a time.

              714.637.9480 x17


              Comment

              • Tom B

                #8
                Re: Server.MapPath returning wrong path

                Windows 2000 server (and I assume 2003) allow more than one site on a
                computer, each usually has it's own public IP

                Windows 2000 and XP professional only allow a single site (Default Web Site)


                "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                news:u$aYQPhfDH A.2248@TK2MSFTN GP09.phx.gbl...[color=blue]
                > "Phillip Windell" <pwindell@wandt v.com> wrote in message
                > news:%23rK8Mmff DHA.128@tk2msft ngp13.phx.gbl.. .
                > ...[color=green]
                > > I've had it do that same to me. If you run a site from a Virtual
                > > Folder instead of an actual Site the MapPath would use the parrent
                > > Site as the starting point instead of the Virtual Directory root. This
                > > is what you would run into with, say, Win2000 Pro where the IIS is
                > > limited to one site, so each separate website runs from its own
                > > Virtual Directory.[/color]
                >
                > Still not clear on what you mean by each separate "website" running in its
                > own virtual directory when you can only have a single web site on the
                > system. Do you mean that there is a way to make it look like there are
                > multiple sites on the system? What would the URLs to 2 separate "websites"
                > look like?
                >
                > --
                > Mark Schupp
                > --
                > Head of Development
                > Integrity eLearning
                > Online Learning Solutions Provider
                > mschupp@ielearn ing.com
                > http://www.ielearning.com
                > 714.637.9480 x17
                >
                >[/color]


                Comment

                • Mark Schupp

                  #9
                  Re: Server.MapPath returning wrong path

                  "Tom B" <shuckle@hotmai l.com> wrote in message
                  news:%23Hit68qf DHA.2252@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                  > Windows 2000 server (and I assume 2003) allow more than one site on a
                  > computer, each usually has it's own public IP
                  >
                  > Windows 2000 and XP professional only allow a single site (Default Web[/color]
                  Site)[color=blue]
                  >
                  >[/color]
                  Yes, I know. What I am curious about is the configuration that is causing
                  the problem. I cannot duplicate it on my systems (2kpro or server).

                  I was trying to find out what the last poster meant by "If you run a site
                  from a Virtual Folder instead of an actual Site".

                  --
                  Mark Schupp
                  --
                  Head of Development
                  Integrity eLearning
                  Online Learning Solutions Provider
                  mschupp@ielearn ing.com
                  Advancing limitless knowledge and continual growth to create confident problem solvers, one course at a time.

                  714.637.9480 x17

                  [color=blue]
                  > "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                  > news:u$aYQPhfDH A.2248@TK2MSFTN GP09.phx.gbl...[color=green]
                  > > "Phillip Windell" <pwindell@wandt v.com> wrote in message
                  > > news:%23rK8Mmff DHA.128@tk2msft ngp13.phx.gbl.. .
                  > > ...[color=darkred]
                  > > > I've had it do that same to me. If you run a site from a Virtual
                  > > > Folder instead of an actual Site the MapPath would use the parrent
                  > > > Site as the starting point instead of the Virtual Directory root. This
                  > > > is what you would run into with, say, Win2000 Pro where the IIS is
                  > > > limited to one site, so each separate website runs from its own
                  > > > Virtual Directory.[/color]
                  > >
                  > > Still not clear on what you mean by each separate "website" running in[/color][/color]
                  its[color=blue][color=green]
                  > > own virtual directory when you can only have a single web site on the
                  > > system. Do you mean that there is a way to make it look like there are
                  > > multiple sites on the system? What would the URLs to 2 separate[/color][/color]
                  "websites"[color=blue][color=green]
                  > > look like?
                  > >
                  > > --
                  > > Mark Schupp
                  > > --
                  > > Head of Development
                  > > Integrity eLearning
                  > > Online Learning Solutions Provider
                  > > mschupp@ielearn ing.com
                  > > http://www.ielearning.com
                  > > 714.637.9480 x17
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Aaron Bertrand [MVP]

                    #10
                    Re: Server.MapPath returning wrong path

                    > Still not clear on what you mean by each separate "website" running in its[color=blue]
                    > own virtual directory when you can only have a single web site on the
                    > system. Do you mean that there is a way to make it look like there are
                    > multiple sites on the system? What would the URLs to 2 separate "websites"
                    > look like?[/color]

                    No, do this.

                    Under the default web site, create a virtual directory called 'foo' which
                    points to somewhere *other* than your normal webroot (e.g. if you use
                    c:\inetpub\wwwr oot\ for your webroot, create a folder called c:\whatever\
                    and use that folder).

                    Now, fuss with the permissions so you can run ASP from that folder, and
                    place an ASP file like this test.asp:

                    <%
                    response.write server.mappath( "/foo/test.asp")
                    %>

                    When you run it, you'll see that it returns something like:

                    c:\inetpub\wwwr oot\foo\test.as p

                    Instead of what I think it should return:

                    c:\whatever\tes t.asp


                    Comment

                    • Mark Schupp

                      #11
                      Re: Server.MapPath returning wrong path

                      Aaron,

                      Still cannot duplicate it. I tried the following on my system against some
                      existing virtual dirs:

                      <%
                      Response.Write "Server.MapPath (""/global.asa""): " &
                      server.MapPath( "/global.asa") & "<br>"
                      Response.Write "Server.MapPath (""kx_gowbt.asp ""): " &
                      server.MapPath( "kx_gowbt.a sp") & "<br>"
                      Response.Write "Server.MapPath (""/kx/kx_gowbt.asp"") : " &
                      server.MapPath( "/kx/kx_gowbt.asp")
                      %>

                      Returns:

                      Server.MapPath( "/global.asa"): C:\Inetpub\wwwr oot\global.asa
                      Server.MapPath( "kx_gowbt.asp") : C:\bw\careertra cker\kx_gowbt.a sp
                      Server.MapPath( "/kx/kx_gowbt.asp"): C:\bw\careertra cker\kx_gowbt.a sp

                      Which, unless I am going completely ga-ga, is correct. Do you think there
                      could be a problem with a specific version of IIS? I am running Win2k/IIS5

                      --
                      Mark Schupp
                      --
                      Head of Development
                      Integrity eLearning
                      Online Learning Solutions Provider
                      mschupp2@ielear ning.com
                      Advancing limitless knowledge and continual growth to create confident problem solvers, one course at a time.

                      714.637.9480 x17


                      "Aaron Bertrand [MVP]" <aaron@TRASHasp faq.com> wrote in message
                      news:eNWjjn7fDH A.3216@tk2msftn gp13.phx.gbl...[color=blue][color=green]
                      > > Still not clear on what you mean by each separate "website" running in[/color][/color]
                      its[color=blue][color=green]
                      > > own virtual directory when you can only have a single web site on the
                      > > system. Do you mean that there is a way to make it look like there are
                      > > multiple sites on the system? What would the URLs to 2 separate[/color][/color]
                      "websites"[color=blue][color=green]
                      > > look like?[/color]
                      >
                      > No, do this.
                      >
                      > Under the default web site, create a virtual directory called 'foo' which
                      > points to somewhere *other* than your normal webroot (e.g. if you use
                      > c:\inetpub\wwwr oot\ for your webroot, create a folder called c:\whatever\
                      > and use that folder).
                      >
                      > Now, fuss with the permissions so you can run ASP from that folder, and
                      > place an ASP file like this test.asp:
                      >
                      > <%
                      > response.write server.mappath( "/foo/test.asp")
                      > %>
                      >
                      > When you run it, you'll see that it returns something like:
                      >
                      > c:\inetpub\wwwr oot\foo\test.as p
                      >
                      > Instead of what I think it should return:
                      >
                      > c:\whatever\tes t.asp
                      >
                      >[/color]


                      Comment

                      • Phillip Windell

                        #12
                        Re: Server.MapPath returning wrong path

                        "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                        news:ugyyCXggDH A.2084@TK2MSFTN GP10.phx.gbl...[color=blue]
                        > Still cannot duplicate it. I tried the following on my system[/color]
                        against some[color=blue]
                        > existing virtual dirs:[/color]

                        To make sure I'm sane ;) I tested it. Here is what I did.

                        Using Win2000 Pro (IIS only allows one Site, but multiple VFs)

                        Home path for the Default Website is "C:\Inetpub\www root"

                        Created a Virtual Folder called "Test"
                        Home path for Virtual Folder is "D:\Temp"

                        Created an ASP file called Test.asp and placed it in "D:\Temp"

                        File contains the line:
                        <%Response.writ e Server.MapPath( "/")%> & "<br>"

                        The output from the page is:
                        "C:\Inetpub\www root"

                        I then added the line:
                        <%Response.Writ e Request.ServerV ariables("APPL_ PHYSICAL_PATH") %>

                        This produced:
                        "D:\Temp\"

                        So the final outcome is that using Server.MapPath will map to the Root
                        of the *Site*, while using
                        Request.ServerV ariables("APPL_ PHYSICAL_PATH") will map to the Root of
                        the *Virtual Folder*. So if the original poster of this thread uses
                        this instead of Server.MapPath his problem would be solved. Now I
                        assume that if either command is used from the Root of the Site they
                        will both produce the same results.

                        --

                        Phillip Windell [CCNA, MVP, MCP]
                        pwindell@wandtv .com
                        WAND-TV (ABC Affiliate)



                        Comment

                        • Mark Schupp

                          #13
                          Re: Server.MapPath returning wrong path

                          Maybe I'm naive but when you use "/" aren't you asking for the root of the
                          site?

                          If you want the root of the virtual directory then you would need
                          "/<virtdir>/".

                          --
                          Mark Schupp
                          --
                          Head of Development
                          Integrity eLearning
                          Online Learning Solutions Provider
                          mschupp2@ielear ning.com
                          Advancing limitless knowledge and continual growth to create confident problem solvers, one course at a time.

                          714.637.9480 x17


                          "Phillip Windell" <pwindell@wandt v.com> wrote in message
                          news:%231KcM8gg DHA.616@TK2MSFT NGP11.phx.gbl.. .[color=blue]
                          > "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                          > news:ugyyCXggDH A.2084@TK2MSFTN GP10.phx.gbl...[color=green]
                          > > Still cannot duplicate it. I tried the following on my system[/color]
                          > against some[color=green]
                          > > existing virtual dirs:[/color]
                          >
                          > To make sure I'm sane ;) I tested it. Here is what I did.
                          >
                          > Using Win2000 Pro (IIS only allows one Site, but multiple VFs)
                          >
                          > Home path for the Default Website is "C:\Inetpub\www root"
                          >
                          > Created a Virtual Folder called "Test"
                          > Home path for Virtual Folder is "D:\Temp"
                          >
                          > Created an ASP file called Test.asp and placed it in "D:\Temp"
                          >
                          > File contains the line:
                          > <%Response.writ e Server.MapPath( "/")%> & "<br>"
                          >
                          > The output from the page is:
                          > "C:\Inetpub\www root"
                          >
                          > I then added the line:
                          > <%Response.Writ e Request.ServerV ariables("APPL_ PHYSICAL_PATH") %>
                          >
                          > This produced:
                          > "D:\Temp\"
                          >
                          > So the final outcome is that using Server.MapPath will map to the Root
                          > of the *Site*, while using
                          > Request.ServerV ariables("APPL_ PHYSICAL_PATH") will map to the Root of
                          > the *Virtual Folder*. So if the original poster of this thread uses
                          > this instead of Server.MapPath his problem would be solved. Now I
                          > assume that if either command is used from the Root of the Site they
                          > will both produce the same results.
                          >
                          > --
                          >
                          > Phillip Windell [CCNA, MVP, MCP]
                          > pwindell@wandtv .com
                          > WAND-TV (ABC Affiliate)
                          > www.wandtv.com
                          >
                          >[/color]


                          Comment

                          • Phillip Windell

                            #14
                            Re: Server.MapPath returning wrong path

                            Ok. Using Server.MapPath( "\test\") produces the Root of the Virtual
                            folder which was "D:\Temp". I noticed that this leaves off the
                            trailing \ while APPL_PHYSICAL_P ATH includes it.

                            So maybe the original poster was using:
                            Server.MapPath( "\") & "\test\somethin g.asp"
                            .... instead of:
                            Server.MapPath( "\test\somethin g.asp")

                            I just tried that and it does reproduce his problem.

                            I don't know, he never showed any code.


                            --

                            Phillip Windell [CCNA, MVP, MCP]
                            pwindell@wandtv .com
                            WAND-TV (ABC Affiliate)


                            "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                            news:eFzP4KhgDH A.3968@tk2msftn gp13.phx.gbl...[color=blue]
                            > Maybe I'm naive but when you use "/" aren't you asking for the root[/color]
                            of the[color=blue]
                            > site?
                            >
                            > If you want the root of the virtual directory then you would need
                            > "/<virtdir>/".
                            >
                            > --
                            > Mark Schupp
                            > --
                            > Head of Development
                            > Integrity eLearning
                            > Online Learning Solutions Provider
                            > mschupp2@ielear ning.com
                            > http://www.ielearning.com
                            > 714.637.9480 x17
                            >
                            >
                            > "Phillip Windell" <pwindell@wandt v.com> wrote in message
                            > news:%231KcM8gg DHA.616@TK2MSFT NGP11.phx.gbl.. .[color=green]
                            > > "Mark Schupp" <mschupp@ielear ning.com> wrote in message
                            > > news:ugyyCXggDH A.2084@TK2MSFTN GP10.phx.gbl...[color=darkred]
                            > > > Still cannot duplicate it. I tried the following on my system[/color]
                            > > against some[color=darkred]
                            > > > existing virtual dirs:[/color]
                            > >
                            > > To make sure I'm sane ;) I tested it. Here is what I did.
                            > >
                            > > Using Win2000 Pro (IIS only allows one Site, but multiple VFs)
                            > >
                            > > Home path for the Default Website is "C:\Inetpub\www root"
                            > >
                            > > Created a Virtual Folder called "Test"
                            > > Home path for Virtual Folder is "D:\Temp"
                            > >
                            > > Created an ASP file called Test.asp and placed it in "D:\Temp"
                            > >
                            > > File contains the line:
                            > > <%Response.writ e Server.MapPath( "/")%> & "<br>"
                            > >
                            > > The output from the page is:
                            > > "C:\Inetpub\www root"
                            > >
                            > > I then added the line:
                            > > <%Response.Writ e[/color][/color]
                            Request.ServerV ariables("APPL_ PHYSICAL_PATH") %>[color=blue][color=green]
                            > >
                            > > This produced:
                            > > "D:\Temp\"
                            > >
                            > > So the final outcome is that using Server.MapPath will map to the[/color][/color]
                            Root[color=blue][color=green]
                            > > of the *Site*, while using
                            > > Request.ServerV ariables("APPL_ PHYSICAL_PATH") will map to the Root[/color][/color]
                            of[color=blue][color=green]
                            > > the *Virtual Folder*. So if the original poster of this thread[/color][/color]
                            uses[color=blue][color=green]
                            > > this instead of Server.MapPath his problem would be solved. Now I
                            > > assume that if either command is used from the Root of the Site[/color][/color]
                            they[color=blue][color=green]
                            > > will both produce the same results.
                            > >
                            > > --
                            > >
                            > > Phillip Windell [CCNA, MVP, MCP]
                            > > pwindell@wandtv .com
                            > > WAND-TV (ABC Affiliate)
                            > > www.wandtv.com
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            Working...