ASP.NET + URL重写:如何处理主题、css、js等资源?
我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,验证您的 RewriteRule 是否仅包含标签。一个简单的解决方法可能是将此 RewriteCond 放在 RewriteRule 之前。
您的样式表链接标记可以很简单:
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.
Your stylesheet link tag can be simply:
处理 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/