asp.net 引入html文件路径问题,asp.net – 在.css文件中引用应用程序相对虚拟路径...

不幸的是,Firefox在这里有一个愚蠢的错误,路径是相对于页面的路径,而不是相对于CSS文件的位置。这意味着如果您在树中具有不同位置的页面(如在根目录中具有Default.aspx,并且在View文件夹中具有Information.aspx),则无法使用工作相对路径。 (IE将正确地解决相对于CSS文件位置的路径。)

re: Making sense of ASP.Net Paths by

Russ Brooks February 25, 2006 @ 8:43

am

No one fully answered Brant’s question

about the image paths inside the CSS

file itself. I’ve got the answer. The

question was, “How do we use

application-relative image paths

INSIDE the CSS file?” I have long been

frustrated by this very problem too,

so I just spent the last 3 hours

working out a solution.

The solution is to run your CSS files

through the ASPX page handler, then

use a small bit of server-side code in

each of the paths to output the root

application path. Ready?

Add to web.config:

Inside your CSS, use the Request.ApplicationPath property

wherever a path exists, like this:

#content {

background: url(

%>/images/bg_content.gif) repeat-y;

}

.NET serves up ASPX pages with a MIME type of “text/html” by default,

consequently, your new server-side CSS

pages are served up with this MIME

type which causes non-IE browsers to

not read the CSS file correctly. We

need to override this to be

“text/css”. Simply add this line as

the first line of your CSS file:

06001

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值