473,695 Members | 2,088 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 15062
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
14317
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
1687
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(" & request.form("MyFileName") & "))
5
3606
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 things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
3
7267
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
1537
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 have a re-director
6
1602
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, 'Server.MapPath' turns into an error "Name 'server' is not declared"
2
1911
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
6242
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
4362
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
8572
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8984
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6491
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.