物理路径,根路径,虚拟路径,相对虚拟路径,应用路径和绝对路径的差异?

时间:2022-06-30 08:28:22

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

在理解.Net中可用于资源的各种路径中的不同之处时,我有些困惑。

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.

我只猜物理路径是资源的OS目录路径。我很困惑,事件无法告诉我基本上需要使用什么路径。

2 个解决方案

#1


5  

The following should provide you with the information you're seeking:

以下内容应为您提供您正在寻找的信息:

Making Sense of ASP.NET Paths

理解ASP.NET路径

#2


11  

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

关于ASP.NET应用程序,我认为它是这样的:

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.

物理路径:使用驱动器/目录/文件的操作系统路径,其中实际的应用程序并不真正使用此路径,但如果确实如此,它将使用虚拟路径进行映射。物理路径是操作系统如何定位资源,即:c:\\ inetpub \ wwwroot \ aspnetapp实际应用程序只关心相对于其根目录的路径。

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.

根路径:这将是您的aspnetapp或〜/ Home / Index的根目录下的URI或URL以及正确的路由配置(不要与Unix根目录命名约定混淆)。 http://www.yardpenalty.com实际上可以是OS / NOS方面的本示例物理路径的位置。

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

虚拟路径或相对虚拟路径:应用程序从其Web服务器识别或标识的路径。

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.

例如,在IIS(或OWIN)中,您可能在文件夹c:\\ inetpub \ ftp \ images中有图像的资源目录,但开发人员将此文件夹映射到应用程序,如此...〜\ Images。因此,请将此视为能够创建应用程序及其用户可识别的资源的相对路径,同时位于其他位置。

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.

绝对路径:资源的完整路径。假设您有一个链接可以将您带到这样的特定路线:关于。如果此链接位于布局或母版页中,则相对路径关于将更加清晰。有些情况下,您需要对绝对路径进行硬编码,但使用相对路径通常更明智,尤其是在开发涉及迁移时。

#1


5  

The following should provide you with the information you're seeking:

以下内容应为您提供您正在寻找的信息:

Making Sense of ASP.NET Paths

理解ASP.NET路径

#2


11  

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

关于ASP.NET应用程序,我认为它是这样的:

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.

物理路径:使用驱动器/目录/文件的操作系统路径,其中实际的应用程序并不真正使用此路径,但如果确实如此,它将使用虚拟路径进行映射。物理路径是操作系统如何定位资源,即:c:\\ inetpub \ wwwroot \ aspnetapp实际应用程序只关心相对于其根目录的路径。

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.

根路径:这将是您的aspnetapp或〜/ Home / Index的根目录下的URI或URL以及正确的路由配置(不要与Unix根目录命名约定混淆)。 http://www.yardpenalty.com实际上可以是OS / NOS方面的本示例物理路径的位置。

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

虚拟路径或相对虚拟路径:应用程序从其Web服务器识别或标识的路径。

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.

例如,在IIS(或OWIN)中,您可能在文件夹c:\\ inetpub \ ftp \ images中有图像的资源目录,但开发人员将此文件夹映射到应用程序,如此...〜\ Images。因此,请将此视为能够创建应用程序及其用户可识别的资源的相对路径,同时位于其他位置。

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.

绝对路径:资源的完整路径。假设您有一个链接可以将您带到这样的特定路线:关于。如果此链接位于布局或母版页中,则相对路径关于将更加清晰。有些情况下,您需要对绝对路径进行硬编码,但使用相对路径通常更明智,尤其是在开发涉及迁移时。