简体   繁体   中英

HttpContext Current Server MapPath : not getting the correct path

Beginner: Need some help in figuring out how can we do it. I am using MVC4 controller with c# and this is happeing in one of my actions

I am trying to get the path of a config file which is located at

 c:\TestProj\www\config\config.xml

I am using this to get the path

var expectedPath = HttpContext.Current.Server.MapPath("~\config\config.xml")

but when i run my action what i am getting in my expected path is

 c:\Test\www\config\config.xml

I am not sure why..can some one please make some suggestions

~ represents the application path.

May be your application is located on c:\\Test\\www. Either place config.xml on C:\\test\\www\\config\\config.xml or move your application to the C:\\testproj folder or use a different method instead of MapPath, that uses absolute path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM