Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I create a web site and mapped it to the
D:\MyWebApp
and in Plugins sub directory I create a virtual directory and mapped it to
D:\Project\Presentation\Web\Accounting
.
the problem is when I want to get the physical path of the phisical path of http://localhost/Plugins/Accounting I get wrong result.
 
both
Server.MapPath("~/Plugins/Accounting") and Server.MapPath("/Plugins/Accounting")
returns
'D:\MyWebApp\Plugins\Accounting'
that does not exist physically. I want to get
D:\Project\Presentation\Web\Accounting
.
I search for it and just get below lines:
 
Server.MapPath(".") returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..") returns the parent directory
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
 
but in my case (virtual directory in a subfolder), it's not work !!!
I use IIS8 and Asp.Net-Mvc 4 and C#4.
how can I do this?
Posted 3-Jul-13 19:26pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Irrespective of version of MVC and IIS, Server.MapPath will always points to root folder of Application. I dont know whats the requirement behind maintaining the plugins in seperate folder, but its not a good practice to maintain different parts of a solution, espicially when you try to reffer it physically.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Server.MapPath doesn't resolve to anything that starts with "http://". It always returns a fully qualified absolute or relative path on disk. This is the "physical path". What you're referring to is a virtual or logical path, not physical. This is something that Server.MapPath will not do.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 16 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100