19

I have some confusion in understanding what is different in various paths available in .Net for a resource.

I only guess Physical path is OS directory path for a resource. I am confuse and event can't tell about what path basically I need to use.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user576510
  • 5,777
  • 20
  • 81
  • 144

2 Answers2

14

In regards to an ASP.NET application I think of it like this:

Physical Path: OS path using drive/directory/file in which the actual app doesnt really use this path but if it did it would be mapped using a virtual path. A physical path is how the OS locates the resource/s ie: c:\\inetpub\wwwroot\aspnetapp The actual app only cares about paths relative to its root directory.

Root Path: This would be the URI or URL at the root of your aspnetapp or ~/Home/Index with proper route config (Not to be confused with Unix Root Directory naming convention). http://www.yardpenalty.com could actually be the location of this example's physical path in terms of an OS/NOS.

Virtual Path or Relative Virtual Path: The path that the application identifies or is identified by from its Web server.

For instance, in IIS (or OWIN) you may have a resource directory for your images in folder c:\\inetpub\ftp\images but the developer maps this folder to the app like so... ~\Images. So think of this as the ability to create a relative path to resources identifiable by your app and its users while physically located elsewhere.

I would imagine that using a virtual path under a root application would be helpful in development when there are one or more projects that the developer wishes to give the appearance of a single application under a single domain.

Absolute Path: The entire path to a resource. Let's say you have a link that takes you to a specific route like this: <a href="http://www.yardpenalty.com/home/about"> About</a>. If this link was in the layout or master page a relative path <a href="~/home/about">About</a> would be cleaner. There are instances when you need to hard code an absolute path but it is typically wiser to use relative paths especially when development involves migrations.

yardpenalty.com
  • 1,244
  • 2
  • 17
  • 32
1

Relative path to the current working directory - Sometimes you can find a path description in a format like this ./Directory/Filename.Ext and it means that the path is specified relatively to the current application working directory.

Honza P.
  • 1,165
  • 1
  • 11
  • 12