473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 9604
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ellen K | last post by:
Hi all, I set up our Oracle Financials as a linked server to one of my SQL Server boxes. On running a test query, I got the following error message: OLE DB provider 'MSDAORA' supplied...
3
by: Mikkky | last post by:
The sample code below returns and error " The type or namspace name 'Server' could not be found". Please help. using System;using System.IO; using System.Xml;using System.Diagnostics; using...
4
by: ramonred | last post by:
txtUpload1.PostedFile.SaveAs(Server.MapPath("~") + "\\" + file1.Name); this code loads the file in the root directory of my application, by using the tilde. How do I accomplish getting the file...
1
by: Jim Heavey | last post by:
Hello, I am trying out how to programatically figure out where my datafile is. I thought I could use Server.MapPath to provide me the name of where my webpage is located, as I have used that in...
2
by: Tee | last post by:
Hi, I am currently using Server.MapPath in my aspx files, but because of I am using it more than once, I would like to move these code away from aspx and make it as a public function inside...
2
by: Jim Moon | last post by:
Hello. We have SQL Server Stored Procedures that use the "CURRENT_USER" variable. We have SQL Server database fields that call "user_name()" as a default. That has been fine in the use and...
10
by: Kenneth P | last post by:
Hi all, I have an Access database and try to create a connection to it using the Server.MapPath method. I have the app lib in c:\inetprub\wwwroot\apps\myApp and the database in...
1
by: ae | last post by:
is the prope way to read xml files, as long as they are on my server, but how do i access them from other sites, such as http://www.site.com/xmltoread.xm
1
by: varathasiva | last post by:
Dear All, I am new in MySQL.I installed mysql-5.0.51b-win32 version.How to configure in MySQL server work as local network or remote server.PostgreSQL we did configuration in pghba.conf host ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.