MapPath returning wrong string

G

GaryDean

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
 
M

Milosz Skalecki [MCAD]

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
 
S

Steven Cheng[MSFT]

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==?=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top