Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get virtual directory physical path

Tags:

asp.net

iis

As we know that a virtual direcoty can be linked to a folder with a diffrent name, how can I get the physical path of a virtual directory ?

I've been trying with HttpContext.Current.server.MapPath but it returns me the physic path plus the path I send in parameter even if the directory doesn't even exist or if it exists with a diffrent name.

Exemple :

C:\blabla\Sites\Application1\Imaageesss - On disc

Application1\Images (In ISS, my virutal directory)

But if I do a MapPath on "/Images" it will never give me C:\blabla\Sites\Application1\Imaageesss but C:\inetpub\wwwroot\Images which is not the real directory linked to.

like image 327
13 revs, 8 users 76% Avatar asked Jun 11 '12 19:06

13 revs, 8 users 76%


People also ask

How do I find virtual directory?

In the Connections pane, expand the server name, expand Sites, expand the Web site to which you want to add the virtual directory, and then click the application to which you want to add the virtual directory. In the Actions pane, click View Virtual Directories, and then click Add Virtual Directory...

How do I find virtual directory in IIS?

You can find more information about virtual directories in Understanding Sites, Applications, and Virtual Directories on IIS 7. On Windows 7: Open Start -> Control Panel -> System and Security category -> Administrative Tools -> Internet Information Services (IIS) Manager.

How do I create a virtual path?

Open IIS Manager by Typing inetmgr on Start Menu or Run. Click On Sites on the Left navigation of IIS Manager. Right Click on Site where you want to Add Virtual Path and Choose Add Virtual Directory. Put the Short Name of Application/Website in Alias Field.

What is physical path and virtual path in asp net?

Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder.


2 Answers

Server.MapPath("~/Images")

is the correct way to go about it as "~" references the root of your application.

like image 193
Tyler Wilson Avatar answered Sep 28 '22 15:09

Tyler Wilson


This is what worked for me:

string physicalPath =    
System.Web.Hosting.HostingEnvironment.MapPath(HttpContext.Current.Request.ApplicationPath);
like image 30
scw Avatar answered Sep 28 '22 15:09

scw