1

我在 Visual Studio 中有一个 ASP.Net 网站解决方案,在尝试时Server.MapPath(@"\");收到以下错误。我知道以前有人问过这个问题,但我还没有找到适合我的解决方案。任何想法都会很棒。

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
4

3 回答 3

5

如果所有其他人建议的解决方案都不起作用,则意味着您的 Visual Studio 没有管理权限。

因此,您可以运行 Visual Studio“以管理员身份运行”并尝试再次执行。

于 2013-03-09T04:01:14.097 回答
3

尝试这个:

Server.mapPath("~/");
于 2013-03-09T03:52:18.763 回答
0

如果此处没有答案如何解决错误消息:“无法映射路径'/'。” 帮忙,试试Server.MapPath(@".\");。这和你的代码对我有用,并产生了相同的结果。

于 2013-03-09T03:53:32.600 回答