Problem with Server.MapPath() in ASP.NET 2.0
-
I built a project in VS 2003 under .NET 1.1 with the following line: ... = Server.MapPath("../includes/navigation_bar.inc"); To be clear, I was referring to the includes directory, located in the directory above my application's root directory. Worked great, that version is still live and running fine. I'm trying to upgrade the program to ASP 2.0 now in VS 2005. The same line gives the following error: System.InvalidOperationException was unhandled by user code Message="Failed to map the path '/includes/navigation_bar.inc'." I've tried for several hours to find a workaround or other solution, but to no avail. Unfortunately, many pages on the website refer to that file, so moving it is not an option. My hunch is that ASP is no longer allowing referrals to files on the server outside of the application's directory, but the purpose behind such a change is puzzling. Any ideas? Anybody know why this is a problem now when it wasn't under .NET 1.1? I appreciate your help! _________________________________________ For information, here are the full details of the error:
System.InvalidOperationException was unhandled by user code Message="Failed to map the path '/includes/navigation_bar.inc'." Source="System.Web" StackTrace: at System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) at System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) at System.Web.VirtualPath.MapPathInternal() at System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) at System.Web.HttpRequest.MapPath(VirtualPath virtualPath) at System.Web.HttpRequest.MapPath(String virtualPath) at Applicators.referrals.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Applicators\referrals.aspx.cs:line 57 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
-
I built a project in VS 2003 under .NET 1.1 with the following line: ... = Server.MapPath("../includes/navigation_bar.inc"); To be clear, I was referring to the includes directory, located in the directory above my application's root directory. Worked great, that version is still live and running fine. I'm trying to upgrade the program to ASP 2.0 now in VS 2005. The same line gives the following error: System.InvalidOperationException was unhandled by user code Message="Failed to map the path '/includes/navigation_bar.inc'." I've tried for several hours to find a workaround or other solution, but to no avail. Unfortunately, many pages on the website refer to that file, so moving it is not an option. My hunch is that ASP is no longer allowing referrals to files on the server outside of the application's directory, but the purpose behind such a change is puzzling. Any ideas? Anybody know why this is a problem now when it wasn't under .NET 1.1? I appreciate your help! _________________________________________ For information, here are the full details of the error:
System.InvalidOperationException was unhandled by user code Message="Failed to map the path '/includes/navigation_bar.inc'." Source="System.Web" StackTrace: at System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) at System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) at System.Web.VirtualPath.MapPathInternal() at System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) at System.Web.HttpRequest.MapPath(VirtualPath virtualPath) at System.Web.HttpRequest.MapPath(String virtualPath) at Applicators.referrals.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Applicators\referrals.aspx.cs:line 57 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Hi there, Are using the File System for your website in the VS 2005? If so, when you debug your application, the VS uses its built-in ASP.NET development server and it can cause the error when you go out of the application boudanry. In this case, you might try to run your application using the IIS server, it should be working.
-
Hi there, Are using the File System for your website in the VS 2005? If so, when you debug your application, the VS uses its built-in ASP.NET development server and it can cause the error when you go out of the application boudanry. In this case, you might try to run your application using the IIS server, it should be working.