2013-03-09 163 views
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 
+0

你在这里做什么'Response.Write(directory)'..? – Sachin 2013-03-09 03:52:19

回答

3

试试这个:

Server.mapPath("~/"); 
+0

我可能需要另一个问题。虽然这确实会返回一条路径,但我在同一个解决方案中有两个网站。分别位于“WebSites \ MMCR \”和“WebSites \ MMCR_Admin \”,我想从一个到另一个访问。我有这个工作之前与mappath,但这次没有运气。 – AzaRoth91 2013-03-09 04:26:15

+0

我需要查看您的代码才能提供任何形式的帮助。 – RouteMapper 2013-03-09 13:01:51

5

如果所有其他人建议解决方案,如果不工作,这意味着您的Visual Studio没有管理特权。

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