IIS 虚拟目录和 ASP.NET 目录路径 [英] IIS virtual directory and ASP.NET directory paths

查看:35
本文介绍了IIS 虚拟目录和 ASP.NET 目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我遇到了典型的虚拟目录困境,因为您在 ASP.Net 应用程序上有一些路径,而您将应用程序部署在 IIS 虚拟目录中.然后所有相对于网络根目录"(例如,/images")的路径都不起作用,因为应用程序位于虚拟目录路径中.

<小时>

解决方案

A. 将images"文件夹设为虚拟目录.这样/images"将永远存在.

B. 使用 "<%=Request.ApplicationPath%>/Imagenes" 作为我的图像来源.这在 IIS 中效果很好,但我在设计时和调试时都看不到它.

此解决方案还包括以下说明:

  • System.Web.VirtualPathUtility.ToAbsolute
  • ResolveClientUrl
  • Request.ApplicationPath

C. 使用当前控件/页面的相对路径.这是确切知道图像文件夹相对于我当前文件的位置(无需转到根目录.所以我会使用诸如"、../"、../../"之类的东西.<小时>

我正在寻找的解决方案

说的.我不喜欢这些解决方案.我想要在 web.config 文件或 IIS 中的解决方案.我在 web.config 文件中写了一些 conf instruction,告诉 IIS 我的应用程序实际驻留的位置(虚拟目录).

有什么建议吗?

解决方案

您是否在可能的地方使用波浪号 (~) 表示路径?

~指的是虚拟Web应用程序的根....

例如~/images.

The problem

I'm running into the typical virtual-directory dilemma in that you have some paths on your ASP.Net application and you deploy the app in a IIS virtual directory. Then all paths relatives to the "web root" (f.i., "/images") doesn't work because the app is in a virtual directory path.


The solutions

A. Make the "images" folder a virtual directory. This way "/images" will always exist.

B. Use "<%=Request.ApplicationPath%>/Imagenes" as the source of my images. This works great in IIS but I can't see it in design-time nor in debug-time.

This solution also include these instructions:

  • System.Web.VirtualPathUtility.ToAbsolute
  • ResolveClientUrl
  • Request.ApplicationPath

C. Use relatives paths to the current control/page. This is know exactly where the images folder is relative to my current file (without go to the root. So I would use things like "", "../", "../../" and so on.


The solution I'm looking for

Said that. I don't like these solutions. I would want a solution in the web.config file or in IIS. Some conf intruction I write in the web.config file that tells IIS where my application resides actually (virtual directory).

Any advice?

解决方案

Are you using the tilde (~) for your paths where you can?

~ refers to the root of the virtual Web application....

~/images for example.

这篇关于IIS 虚拟目录和 ASP.NET 目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆