IIS 虚拟目录和 ASP.NET 目录路径
我遇到的问题
是典型的虚拟目录困境,因为您的 ASP.Net 应用程序上有一些路径,并且您将应用程序部署在 IIS 虚拟目录中。然后,与“Web 根”(fi、“/images”)相关的所有路径都不起作用,因为该应用程序位于虚拟目录路径中。
解决方案
A. 将“images”文件夹设为虚拟目录。这样“/images”将永远存在。
B. 使用“<%=Request.ApplicationPath%>/Imagenes”
作为我的图像来源。这在 IIS 中工作得很好,但我在设计时和调试时都看不到它。
此解决方案还包括以下说明:
- System.Web.VirtualPathUtility.ToAbsolute
- ResolveClientUrl
- Request.ApplicationPath
C. 使用当前控件/页面的相对路径。这是确切知道图像文件夹相对于我当前文件的位置(无需转到根目录。所以我会使用“”、“../”、“../../”等内容。
解决方案我正在寻找
说,我不喜欢这些解决方案,我希望在 web.config 文件或 IIS 中找到一些解决方案,告诉 IIS 我的应用程序实际驻留在哪里。 )。
(虚拟目录
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尽可能使用波形符 (~) 作为路径?
~ 指的是虚拟 Web 应用程序的根目录...
例如 ~/images。
Are you using the tilde (~) for your paths where you can?
~ refers to the root of the virtual Web application....
~/images for example.
如果它仅适用于客户端的 css 文件,那么使用 url 指令会使路径相对于样式表而不是页面的路径:
此外,如果您使用的是 asp.net mvc,那么您可以访问:
If it's just for css files on the client side then using the url directive makes the path relative to that of the style sheet rather than the page:
Also if you're on asp.net mvc then you have access to: