Click here to Skip to main content
13,055,861 members (50,069 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I create a web site and mapped it to the
and in Plugins sub directory I create a virtual directory and mapped it to
the problem is when I want to get the physical path of the phisical path of http://localhost/Plugins/Accounting I get wrong result.

Server.MapPath("~/Plugins/Accounting") and Server.MapPath("/Plugins/Accounting")
that does not exist physically. I want to get
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 18:26pm
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...?
Rate this: bad
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.
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Jul 2014
Copyright © CodeProject, 1999-2017
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