IIS 7 Web站点下的Web应用程序中的相对路径 [英] Relative paths in IIS 7 Web applications under a website

查看:1367
本文介绍了IIS 7 Web站点下的Web应用程序中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制网站下的网络应用程序中的路径解析应用程序下的实际路径,而不是网站?

Is there a way to force "Paths" in a web-application under a website to resolve to actual paths under the app, rather than the site?

I我是新的所以我无法上传我正在谈论的图像,但看看你是否可以看到我的IIS设置:

I'm new so I can't upload an image of what I'm talking about, but see if you can visualize my IIS setup:

IIS 7.0
----MAIN WEB SITE:
    ----Web App #1
    ----Web App #2

每个网络应用都有自己的CSS,指向自己的图像;例如在Web App#1中:

Each web app has its own CSS, pointing to its own images; for example in Web App #1:

background-image: url(images/someimage.png)

问题是,由于网络应用程序安装在主站点下,images / someimage.png解析为图像文件夹主网站,而不是网络应用程序#1。

The problem is, since web app is installed under a main site, "images/someimage.png" resolves to the image folder of the main site, not web app #1.

我该如何解决这个问题?

How can I fix this?

推荐答案

首先尝试这个

Asp.net初学者的路径有一些内容

UPDATE(因为我也在努力解决这个问题):

UPDATE(as I'm struggling with this too):

除了MapPath背后的代码(〜/ ...)之外,我的焦点只来自HTML / CSS的路径分辨率

Besides code behind MapPath("~/..."), my focus was only from HTML/CSS point of path resolution

我注意到,如果我们谈论HTML

I noticed if we talking about HTML

<img src="/images/x.jpg" />  this will work only from  

IIS 7.0
----MAIN WEB SITE

images前面的斜杠/将被解释为go to root

The slash "/" in front of "images" will be interpreted "go to root"

以修复

IIS 7.0
----MAIN WEB SITE
    ----Web App #1

删除/所以< img src =images / x.jpg/> 这将适用于两者,当作为网站托管和作为Web应用程序托管时

remove "/" so <img src="images/x.jpg" /> this will work for both, when hosted as site and when hosted as web application

现在CSS很棘手不同的方式,我是很惊讶,使用你的例子它不起作用,因为图像前没有斜线。

Now CSS is tricky different way, I was surprised that using your example it doesn't work since there is no slash in front of the images.

考虑一个基于你的例子的结构

consider a structure based on your expample

IIS 7.0
----MAIN WEB SITE:
    ----Web App #1
        ----styles
        ----images

你的CSS

background-image: url(images/someimage.png)

告诉浏览器查看for MAIN WEB SITE / Web App#1 / styles / images / someimage.png

tells the browser to look for MAIN WEB SITE/Web App #1/styles/images/someimage.png

add/ background-image:url(/images/someimage.png)

结果是 MAIN WEB SITE / images / someimage.png

现在添加../ background-image:url(。 ./images/someimage.png)

结果是 MAIN WEB SITE / Web App#1 / images / someimage.png

(好像已经解决了一个级别,然后转到图像)

(seems like resolved as go one level up, and then go to images)

好的一面是,一旦你更改了这些前缀以使其作为Web应用程序工作,即使你作为实际的网站托管,它似乎也可以工作

The good part is, that once you change those prefixes to make it work as web application it seems to work even when hosted as actual web site if you need to do so

IIS 7.0
----MAIN WEB SITE (web app #1):
    ----styles
    ----images

[抱歉,如果这个答案不够描述或杂乱,我会在有人时加编辑会提出或者如果我自己发现错误,一般是firefox / chrome F12并查看路径s for resources]

[Sorry if this answer is not descriptive enough or messy, I will add edits when someone will propose or if I notice mistakes myself, generally firefox/chrome F12 and see paths for resources]

这篇关于IIS 7 Web站点下的Web应用程序中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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