Server.MapPath("/") doesnt work

M

MichiMichi

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.vb
Line: 10

Stack Trace:


[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

MichiMichi said:
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.vb
Line: 10

Stack Trace:


[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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?
 
M

MichiMichi

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

MichiMichi said:
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

Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.vb
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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?
 
K

Kevin Spencer

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.

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

MichiMichi said:
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

Source File: C:\Documents and Settings\machine.namei\My Documents
\Visual Studio 2005\WebSites\testing\phishingPics\Default2.aspx.vb
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

MichiMichi said:
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

MichiMichi said:
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.vb
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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?
 
M

MichiMichi

I am now using the "~" instead of "/".

Microsoft should change its documentation as well.

Thanks for helping.


MichiMichi said:
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
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.vb
Line: 10
Stack Trace:
[InvalidOperationException: Failed to map the path '/app_test'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top