473,573 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Oct 6 '07 #1
3 15055
Hello rn**@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

Oct 6 '07 #2
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" <ne*****@msn.co mwrote in message news:3d******** *************** **@msnews.micro soft.com...
Hello rn**@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



Oct 6 '07 #3
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:3d* *************** *********@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

Oct 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
14305
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product 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\wwwroot rather than the real path. Can anyone please tell me why this isn't working? Regards, John
3
1684
by: Jake | last post by:
How can I pass the results of a form field submitted to this statement below? <% Set MyFileObj = Server.CreateObject("Scripting.FileSystemObject") '### This Works '###Set MyTextFile = MyFileObj.OpenTextFile(Server.MapPath("body.txt")) '### This Doesnt work Set MyTextFile = MyFileObj.OpenTextFile(Server.MapPath(" &...
5
3592
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of...
3
7264
by: Kian Goh | last post by:
Hi, Can somebody tell me why can't I use string strPath = Server.MapPath(Request.ApplicationPath); in protected void Application_Start(...) It compiles ok but an unhandled exception occurred during the execution. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
0
1528
by: Carl Gilbert | last post by:
Hi I am trying to get an online gallery to work (www.ngallery.org). I have managed to get it all working on my local host but I can not get it to work on my web space. The site can be found at www.gallerox.com which should re-direct to www.gallerox.com/gallerox/default.aspx I have put the bin directory in the /gallerox folder as I...
6
1598
by: darrel | last post by:
I have some functions that are reading/writing to the file system. As such, they use server.mapPath a lot to navigate it all. Since I'm using these functions numerous times throughout my application, I thought I'd move these into their own .vb class file and reference them that way. The catch is when moving these scripts over,...
2
1902
by: WB | last post by:
Hi, How can I access Server and Trace within a helper class? I have a webform that allows user to select a PDF file (on the web server) and render a jpeg image of that PDF file. The helper class has a method like this: public void ProcessFile(string virtualPath, string outputFilename) {
7
6235
by: teo | last post by:
I need to use the 'Server.MapPath' function in the 'Session_End' event of the Global.asax file (to reach a folder and the clean some temporary files up), but it doesn't work: Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Dim myPath As String = (Server.MapPath("../public/MyFolder/") End Sub
2
4360
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
Can anyone tell me the difference between server.mappath and request.mappath? Why would I use one vs. the other?
0
7767
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7684
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8006
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7768
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5579
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1035
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.