Saturday, March 24, 2012

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\\AnonymousAccess \\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
GaryHi 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:

Quote:

Originally Posted by

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\\AnonymousAccess \\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
>
>
>


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.

-------

Quote:

Originally Posted by

>From: =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=


<mily242@.DONTLIKESPAMwp.pl>

Quote:

Originally Posted by

>References: <#gqo5ucNIHA.1168@.TK2MSFTNGP02.phx.gbl>
>Subject: RE: MapPath returning wrong string
>Date: Mon, 3 Dec 2007 15:28:03 -0800


Quote:

Originally Posted by

>
>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:
>

Quote:

Originally Posted by

>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\\AnonymousAccess \\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
>>
>>
>>


>

0 comments:

Post a Comment