Server.MapPath & Request.MapPath

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rn5a@rediffmail.com

    Server.MapPath & Request.MapPath

    Server.MapPath returns the physical file path that corresponds to the
    specified virtual path whereas Request.MapPath maps the specified
    virtual path to a physical path. Assuming that a file named Hello.aspx
    resides in C:\Inetpub\wwwr oot\MyFolder, the output of both

    Response.Write( Server.MapPath( "Hello.aspx "))

    &

    Response.Write( Request.MapPath ("Hello.aspx "))

    is C:\Inetpub\wwwr oot\MyFolder\He llo.aspx. So what's the difference
    between Server.MapPath & Request.MapPath ?

    Thanks

  • Michael Nemtsev

    #2
    Re: Server.MapPath & Request.MapPath

    Hello rn5a@rediffmail .com,

    There are no difference in this aspect, because the Server.MapPath calls the
    _context.Reques t.MapPath(path)
    inside its method

    ---
    WBR,
    Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo

    Server.MapPath returns the physical file path that corresponds to the
    specified virtual path whereas Request.MapPath maps the specified
    virtual path to a physical path. Assuming that a file named Hello.aspx
    resides in C:\Inetpub\wwwr oot\MyFolder, the output of both
    >
    Response.Write( Server.MapPath( "Hello.aspx "))
    >
    &
    >
    Response.Write( Request.MapPath ("Hello.aspx "))
    >
    is C:\Inetpub\wwwr oot\MyFolder\He llo.aspx. So what's the difference
    between Server.MapPath & Request.MapPath ?
    >
    Thanks
    >

    Comment

    • Juan T. Llibre

      #3
      Re: Server.MapPath & Request.MapPath

      The way I look at it, there's a single MapPath method
      which is called in different contexts with different parameters.

      public virtual string MapPath(string virtualPath)
      {
      return null;
      }

      public string MapPath(string virtualPath)
      {
      return this.MapPath(Vi rtualPath.Creat eAllowNull(virt ualPath));
      }

      internal string MapPath(Virtual Path virtualPath)
      {
      if (this._wr != null)
      {
      return this.MapPath(vi rtualPath, this.FilePathOb ject, true);
      }
      return virtualPath.Map Path();
      }

      public string MapPath(string virtualPath, string baseVirtualDir, bool allowCrossAppMa pping)
      {
      VirtualPath filePathObject;
      if (string.IsNullO rEmpty(baseVirt ualDir))
      {
      filePathObject = this.FilePathOb ject;
      }
      else
      {
      filePathObject = VirtualPath.Cre ateTrailingSlas h(baseVirtualDi r);
      }
      return this.MapPath(Vi rtualPath.Creat eAllowNull(virt ualPath), filePathObject, allowCrossAppMa pping);
      }

      internal string MapPath(Virtual Path virtualPath, VirtualPath baseVirtualDir, bool allowCrossAppMa pping)
      {
      if (this._wr == null)
      {
      throw new HttpException(S R.GetString("Ca nnot_map_path_w ithout_context" ));
      }
      if (virtualPath == null)
      {
      virtualPath = VirtualPath.Cre ate(".");
      }
      VirtualPath path = virtualPath;
      if (baseVirtualDir != null)
      {
      virtualPath = baseVirtualDir. Combine(virtual Path);
      }
      if (!allowCrossApp Mapping)
      {
      virtualPath.Fai lIfNotWithinApp Root();
      }
      string str = virtualPath.Map PathInternal();
      if (((virtualPath. VirtualPathStri ng == "/") && (path.VirtualPa thString != "/"))
      && (!path.HasTrail ingSlash && UrlPath.PathEnd sWithExtraSlash (str)))
      {
      str = str.Substring(0 , str.Length - 1);
      }
      InternalSecurit yPermissions.Pa thDiscovery(str ).Demand();
      return str;
      }

      public string MapPath(string path)
      {
      if (this._context == null)
      {
      throw new HttpException(S R.GetString("Se rver_not_availa ble"));
      }
      return this._context.R equest.MapPath( path);
      }

      public string MapPath()
      {
      return HostingEnvironm ent.MapPath(thi s);
      }



      Juan T. Llibre, asp.net MVP
      asp.net faq : http://asp.net.do/faq/
      foros de asp.net, en espanol : http://asp.net.do/foros/
      =============== =============== ========
      "Michael Nemtsev" <nemtsev@msn.co mwrote in message news:3d9fba1aec 828c9d64fc67e45 f0@msnews.micro soft.com...
      Hello rn5a@rediffmail .com,
      >
      There are no difference in this aspect, because the Server.MapPath calls the _context.Reques t.MapPath(path)
      inside its method
      >
      ---
      WBR, Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
      "The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we
      reach it" (c) Michelangelo
      >
      >Server.MapPa th returns the physical file path that corresponds to the
      >specified virtual path whereas Request.MapPath maps the specified
      >virtual path to a physical path. Assuming that a file named Hello.aspx
      >resides in C:\Inetpub\wwwr oot\MyFolder, the output of both
      >>
      >Response.Write (Server.MapPath ("Hello.aspx "))
      >>
      >&
      >>
      >Response.Write (Request.MapPat h("Hello.aspx") )
      >>
      >is C:\Inetpub\wwwr oot\MyFolder\He llo.aspx. So what's the difference
      >between Server.MapPath & Request.MapPath ?
      >>
      >Thanks
      >>
      >
      >




      Comment

      • rn5a@rediffmail.com

        #4
        Re: Server.MapPath &amp; Request.MapPath

        On Oct 6, 6:45 am, "Juan T. Llibre" <nomailrepl...@ nowhere.comwrot e:
        The way I look at it, there's a single MapPath method
        which is called in different contexts with different parameters.
        >
        public virtual string MapPath(string virtualPath)
        {
        return null;
        >
        }
        >
        public string MapPath(string virtualPath)
        {
        return this.MapPath(Vi rtualPath.Creat eAllowNull(virt ualPath));
        >
        }
        >
        internal string MapPath(Virtual Path virtualPath)
        {
        if (this._wr != null)
        {
        return this.MapPath(vi rtualPath, this.FilePathOb ject, true);
        }
        return virtualPath.Map Path();
        >
        }
        >
        public string MapPath(string virtualPath, string baseVirtualDir, bool allowCrossAppMa pping)
        {
        VirtualPath filePathObject;
        if (string.IsNullO rEmpty(baseVirt ualDir))
        {
        filePathObject = this.FilePathOb ject;
        }
        else
        {
        filePathObject = VirtualPath.Cre ateTrailingSlas h(baseVirtualDi r);
        }
        return this.MapPath(Vi rtualPath.Creat eAllowNull(virt ualPath), filePathObject, allowCrossAppMa pping);
        >
        }
        >
        internal string MapPath(Virtual Path virtualPath, VirtualPath baseVirtualDir, bool allowCrossAppMa pping)
        {
        if (this._wr == null)
        {
        throw new HttpException(S R.GetString("Ca nnot_map_path_w ithout_context" ));
        }
        if (virtualPath == null)
        {
        virtualPath = VirtualPath.Cre ate(".");
        }
        VirtualPath path = virtualPath;
        if (baseVirtualDir != null)
        {
        virtualPath = baseVirtualDir. Combine(virtual Path);
        }
        if (!allowCrossApp Mapping)
        {
        virtualPath.Fai lIfNotWithinApp Root();
        }
        string str = virtualPath.Map PathInternal();
        if (((virtualPath. VirtualPathStri ng == "/") && (path.VirtualPa thString != "/"))
        && (!path.HasTrail ingSlash && UrlPath.PathEnd sWithExtraSlash (str)))
        {
        str = str.Substring(0 , str.Length - 1);
        }
        InternalSecurit yPermissions.Pa thDiscovery(str ).Demand();
        return str;
        >
        }
        >
        public string MapPath(string path)
        {
        if (this._context == null)
        {
        throw new HttpException(S R.GetString("Se rver_not_availa ble"));
        }
        return this._context.R equest.MapPath( path);
        >
        }
        >
        public string MapPath()
        {
        return HostingEnvironm ent.MapPath(thi s);
        >
        }
        >
        Juan T. Llibre, asp.net MVP
        asp.net faq :http://asp.net.do/faq/
        foros de asp.net, en espanol :http://asp.net.do/foros/
        =============== =============== ========
        >
        >
        >
        "Michael Nemtsev" <nemt...@msn.co mwrote in messagenews:3d9 fba1aec828c9d64 fc67e45f0@msnew s.microsoft.com ...
        Hello r...@rediffmail .com,
        >
        There are no difference in this aspect, because the Server.MapPath calls the _context.Reques t.MapPath(path)
        inside its method
        >
        ---
        WBR, Michael Nemtsev [.NET/C# MVP] :: blog:http://spaces.live.com/laflour
        "The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we
        reach it" (c) Michelangelo
        >
        Server.MapPath returns the physical file path that corresponds to the
        specified virtual path whereas Request.MapPath maps the specified
        virtual path to a physical path. Assuming that a file named Hello.aspx
        resides in C:\Inetpub\wwwr oot\MyFolder, the output of both
        >
        Response.Write( Server.MapPath( "Hello.aspx "))
        >
        &
        >
        Response.Write( Request.MapPath ("Hello.aspx "))
        >
        is C:\Inetpub\wwwr oot\MyFolder\He llo.aspx. So what's the difference
        between Server.MapPath & Request.MapPath ?
        >
        Thanks- Hide quoted text -
        >
        - Show quoted text -
        Thanks both of you for your inputs but Juan, being a ASP.NET newbie,
        your response has left me in a tizzy! More so because I use VB.NET &
        not C# & all the C# code you have cited has left me further confused!

        BTW, I have come across the word "context" numerous times since I have
        started learning ASP.NET but to be honest, I don't understand what
        does it exactly mean. Can someone please explain me what does
        "context" mean with respect to .NET? As such, I know what does
        "context" mean in English!

        If giving examples, please try using VB & not C#.

        Ron

        Comment

        Working...