ASP.NET + URL重写:如何处理主题、css、js等资源?

发布于 2024-08-23 06:10:26 字数 423 浏览 2 评论 0原文

我已经使用 Helicon ISAPI Rewrite v3 编写了 URL,如下所示:

www.foo.com/tags/tag1 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1

但是我引用的 .css、.js 正在被浏览器访问,

www.foo.com/tags/tag1/style.css
www.foo.com/tags/tag1/myjs.js

但这些文件位于

www.foo.com/css/style.css
www.foo.com/js/myjs.js

没有硬编码域名“www.foo.com”的情况下,如何我可以实现错误引用吗?

I've written URL using Helicon ISAPI Rewrite v3 for following:

www.foo.com/tags/tag1 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1

But the .css, .js i've refered are being accessed by browser as

www.foo.com/tags/tag1/style.css
www.foo.com/tags/tag1/myjs.js

but these files are located as

www.foo.com/css/style.css
www.foo.com/js/myjs.js

Without hardcoding the domain name "www.foo.com", how i can achieve wrong referencing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦初醒的夏天 2024-08-30 06:10:26

首先,验证您的 RewriteRule 是否仅包含标签。一个简单的解决方法可能是将此 RewriteCond 放在 RewriteRule 之前。

RewriteCond %{REQUEST_FILENAME} !(.js|.css|.gif|.jpg)

您的样式表链接标记可以很简单:

  <link href="/css/style.css" rel="stylesheet" type="text/css" />

First, verify that your RewriteRule is not including more than just tags. A simple fix might be to put this RewriteCond on the line before your RewriteRule.

RewriteCond %{REQUEST_FILENAME} !(.js|.css|.gif|.jpg)

Your stylesheet link tag can be simply:

  <link href="/css/style.css" rel="stylesheet" type="text/css" />
阳光下的泡沫是彩色的 2024-08-30 06:10:26

处理 CSS 和其他静态文件(即图像和 javascript)的一个技巧是在页面的 head 部分包含一个基本标签,例如

这样,您的所有 CSS 路径等都将相对于基本标记中的 href 进行解析。

想要了解更多信息你可以查看这个帖子:
http://chriscavanagh.wordpress.com/2008 /11/06/aspnet-routing-just-enough-rope/

One trick for handling CSS and other static files i.e. images and javascript, is to include a base tag in the head section of your page e.g.

That way, all your CSS paths, etc. will be resolved relative to the href in the base tag.

For more info you can check this post:
http://chriscavanagh.wordpress.com/2008/11/06/aspnet-routing-just-enough-rope/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文