469,623 Members | 980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Server.MapPath("/") doesnt work

When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error

Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")

However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for

Server.MapPath("/app_test")

Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10

Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System

What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005

Feb 12 '07 #1
5 9397
MichiMichi wrote:
When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error

Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")

However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for

Server.MapPath("/app_test")

Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10

Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System

What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005
Do you need to use that exact path? What folder is it that you want to
reach?

--
Göran Andersson
_____
http://www.guffa.com
Feb 12 '07 #2
I want to reach the root folder of my web application.

Response.Write(Server.MapPath("~") works fine but I thought it also
would work with Response.Write(Server.MapPath("/") but it doesnt?

It works on IIS but not with the intern web server of VS2005

On Feb 12, 4:49 am, Göran Andersson <g...@guffa.comwrote:
MichiMichi wrote:
When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error
Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")
However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for
Server.MapPath("/app_test")
Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System
What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005

Do you need to use that exact path? What folder is it that you want to
reach?

--
Göran Andersson
_____http://www.guffa.com

Feb 12 '07 #3
Why not use the method that works? The old method doesn't work because a
path beginning with a forward-slash is a site-root relative path. An ASP.Net
application is not a (web) site root. It is simply a designation of a
virtual directory as housing resources that will be processed in the same
application domain (memory space). The tilde ('~') indicates that the path
is relative to the application root.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

"MichiMichi" <ww*****@gmx.chwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
I want to reach the root folder of my web application.

Response.Write(Server.MapPath("~") works fine but I thought it also
would work with Response.Write(Server.MapPath("/") but it doesnt?

It works on IIS but not with the intern web server of VS2005

On Feb 12, 4:49 am, Göran Andersson <g...@guffa.comwrote:
MichiMichi wrote:
When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error
Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")
However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for
Server.MapPath("/app_test")
Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System
What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005

Do you need to use that exact path? What folder is it that you want to
reach?

--
Göran Andersson
_____http://www.guffa.com


Feb 12 '07 #4
MichiMichi wrote:
I want to reach the root folder of my web application.
Then you should use "~", not "/".

If you use "/" you will get to the root folder of the web site, but if
your application is in a virtual folder, you will get the wrong address.
Response.Write(Server.MapPath("~") works fine but I thought it also
would work with Response.Write(Server.MapPath("/") but it doesnt?

It works on IIS but not with the intern web server of VS2005

On Feb 12, 4:49 am, Göran Andersson <g...@guffa.comwrote:
>MichiMichi wrote:
>>When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error
Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")
However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for
Server.MapPath("/app_test")
Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System
What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005
Do you need to use that exact path? What folder is it that you want to
reach?

--
Göran Andersson
_____http://www.guffa.com


--
Göran Andersson
_____
http://www.guffa.com
Feb 12 '07 #5
I am now using the "~" instead of "/".

Microsoft should change its documentation as well.

Thanks for helping.
On Feb 12, 1:29 pm, Göran Andersson <g...@guffa.comwrote:
MichiMichi wrote:
I want to reach the root folder of my web application.

Then you should use "~", not "/".

If you use "/" you will get to the root folder of the web site, but if
your application is in a virtual folder, you will get the wrong address.
Response.Write(Server.MapPath("~") works fine but I thought it also
would work with Response.Write(Server.MapPath("/") but it doesnt?
It works on IIS but not with the intern web server of VS2005
On Feb 12, 4:49 am, Göran Andersson <g...@guffa.comwrote:
MichiMichi wrote:
When using Server.MapPath on IIS 5 on my localhost everything works
well. All of the following commands are executed without any error
Response.Write(Server.MapPath("/app_test") & "<br>")
Response.Write(Server.MapPath("app_test") & "<br>")
Response.Write(Server.MapPath("~") & "<br>")
However, running the first statement on via the internal Visual Studio
2005 Server I receive an error for
Server.MapPath("/app_test")
Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.v b
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActua l(VirtualPath
virtualPath, Boolean permitNull) +3521356
System.Web.VirtualPath.MapPathInternal() +41
System
What can I do to make this work on my testing enviroment with the
light weight webserver on Visual Studio 2005
Do you need to use that exact path? What folder is it that you want to
reach?
--
Göran Andersson
_____http://www.guffa.com

--
Göran Andersson
_____http://www.guffa.com

Feb 14 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mikkky | last post: by
4 posts views Thread by ramonred | last post: by
1 post views Thread by Jim Heavey | last post: by
2 posts views Thread by Jim Moon | last post: by
10 posts views Thread by Kenneth P | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.