Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Tom Laperre 21-Jan-15 9:27am    
Did you find a solution for this, I need to do the same thing. The idee is to get folder-file content from a virtual directory other then de web application folder...?

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.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900