AzaRoth91
AzaRoth91

Reputation: 283

Failed to map the path '/'

I have an ASP.Net website solution in Visual Studio, and when trying to Server.MapPath(@"\");I receive the following error. I know this question has been asked before but I am yet to find a solution that has worked for me. Any ideas would be great.

Failed to map the path '/'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Failed to map the path '/'.

Source Error: 


Line 10:     protected void Page_Load(object sender, EventArgs e)
Line 11:     {
Line 12:       string directory = Server.MapPath(@"\");
Line 13:       Response.Write(directory);
Line 14:     }

Source File: c:\Users\Josh\Documents\Visual Studio 2010\WebSites\MMCR\About.aspx.cs    Line: 12 

Stack Trace: 


[InvalidOperationException: Failed to map the path '/'.]
   System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +8937646
   System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) +42
   System.Web.VirtualPath.MapPathInternal() +4
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +107
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath) +37
   System.Web.HttpServerUtility.MapPath(String path) +99
   About.Page_Load(Object sender, EventArgs e) in c:\Users\Josh\Documents\Visual Studio 2010\WebSites\MMCR\About.aspx.cs:12
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Upvotes: 1

Views: 13810

Answers (3)

Smaug
Smaug

Reputation: 2673

If all of the others suggested solution if not working it means that your Visual Studio doesn't have a administrative privileged.

Hence you may run the Visual Studio "Run as Administrator" and try to execute once again.

Upvotes: 5

adrianz
adrianz

Reputation: 109

if none of the answers here How to solve error message: "Failed to map the path '/'." help, try Server.MapPath(@".\");. This and your code worked for me, and produced the same results.

Upvotes: 0

RouteMapper
RouteMapper

Reputation: 2560

Try this:

Server.mapPath("~/");

Upvotes: 3

Related Questions