469,890 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

MapPath returning wrong string

The following command...
string DebugString =
System.Web.HttpContext.Current.Server.MapPath("App _Themes");
is executed from my ThemeManager.cs class in my App_code directory

It returns...
"c:\\inetpub\\wwwroot\\TaxBusiness\\AnonymousAcces s\\App_Themes"

The folders in my website project are...
Admin
AnonymousAccess
App_Code
App_Data
App_Themes
Bin.. etc

MapPath should have returned...
"c:\\inetpub\\wwwroot\\TaxBusiness\\App_Themes "

Why did it stick the extra \\AnonymousAccess directory in there?
App_Themes is a direct child of the TaxBusiness website directory

Thanks
Gary
Dec 3 '07 #1
2 2581
Hi Gary,

Is there a possibility ThemeManager.cs class was used from a page/user
control inside the AnonymousAccess directory? You should have used :
string DebugString =
System.Web.HttpContext.Current.Server.MapPath("~/App_Themes");

Hope it helps
--
Milosz
"GaryDean" wrote:
The following command...
string DebugString =
System.Web.HttpContext.Current.Server.MapPath("App _Themes");
is executed from my ThemeManager.cs class in my App_code directory

It returns...
"c:\\inetpub\\wwwroot\\TaxBusiness\\AnonymousAcces s\\App_Themes"

The folders in my website project are...
Admin
AnonymousAccess
App_Code
App_Data
App_Themes
Bin.. etc

MapPath should have returned...
"c:\\inetpub\\wwwroot\\TaxBusiness\\App_Themes "

Why did it stick the extra \\AnonymousAccess directory in there?
App_Themes is a direct child of the TaxBusiness website directory

Thanks
Gary
Dec 3 '07 #2
Thanks for Milosz's input.

Hi Gary,

I agree with Milosz that you're recommended to utilize the "~" symbol of
ASP.NET, Server.MapPath("~/subdir") can give you any subdir's physical path
from your application's root directory. Relative path is not quite safe
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
<mi*****@DONTLIKESPAMwp.pl>
>References: <#g**************@TK2MSFTNGP02.phx.gbl>
Subject: RE: MapPath returning wrong string
Date: Mon, 3 Dec 2007 15:28:03 -0800
>
Hi Gary,

Is there a possibility ThemeManager.cs class was used from a page/user
control inside the AnonymousAccess directory? You should have used :
string DebugString =
System.Web.HttpContext.Current.Server.MapPath(" ~/App_Themes");

Hope it helps
--
Milosz
"GaryDean" wrote:
>The following command...
string DebugString =
System.Web.HttpContext.Current.Server.MapPath("Ap p_Themes");
is executed from my ThemeManager.cs class in my App_code directory

It returns...
"c:\\inetpub\\wwwroot\\TaxBusiness\\AnonymousAcce ss\\App_Themes"

The folders in my website project are...
Admin
AnonymousAccess
App_Code
App_Data
App_Themes
Bin.. etc

MapPath should have returned...
"c:\\inetpub\\wwwroot\\TaxBusiness\\App_Themes "

Why did it stick the extra \\AnonymousAccess directory in there?
App_Themes is a direct child of the TaxBusiness website directory

Thanks
Gary
Dec 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by John Rebbeck | last post: by
6 posts views Thread by JR | last post: by
6 posts views Thread by Nathan Sokalski | last post: by
14 posts views Thread by Lorenzo | last post: by
3 posts views Thread by rn5a | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.