RouteHandler 与相对路径冲突
我的项目(某些东西)中有一个与此类似的目录结构:
Root
|
|- Utilities
|
|- Modules
|
|- Admin
在 admin 目录中,我有一个简单的页面 default.aspx
和一个 javascript 文件 validation.js
我只是想在我的 aspx 页面中引用这个文件,
<script src="validation.js" ...></script>
因为我正在使用路由处理程序,我的 url 将像这个模板一样
http://mysubdomain.mysite.com/admin/UserId/manage
(用三重 des 加密字符串替换 userid 并设置),
所以因为正在使用相对路径要访问js文件,当我尝试签入firebug时,它尝试使用此路径访问js文件:
http://mysubdomain.mysite.com/admin/UserId/manage/validation.js
当然,它不存在。我看到的唯一方法是
src="\modules\admin\validation.js"
肯定指定完整的相对路径,应该有某种方法可以在没有完整相对路径的情况下使用此验证js。如何得到它?
谢谢。
ps:这全部在 .aspx
页面中,而不是代码隐藏 (.cs)
I have a directory structure in my project (something) similar to this one:
Root
|
|- Utilities
|
|- Modules
|
|- Admin
in the admin directory, I have a simple page default.aspx
and a javascript file validation.js
I am just trying to refer to this file in my aspx page like
<script src="validation.js" ...></script>
since I am using route handlers, my url will be like this template
http://mysubdomain.mysite.com/admin/UserId/manage
(replace userid with a triple des encrypted string and you are set)
so since the relative path is being used to access the js file, when I try to check in firebug, its trying to access the js file with this path:
http://mysubdomain.mysite.com/admin/UserId/manage/validation.js
of course, its not present. the only way I see is to specify full relative path
src="\modules\admin\validation.js"
surely, there should be some way I can use this validation js without the full relative path. How to get that?
thanks.
ps: this is all in .aspx
page and not codebehind (.cs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到过这个问题,但始终无法采取任何措施。我通常最终使用完整的相对路径,如果目录发生变化,那么我每次都必须手动更改它。我认为没有其他方法可以做到这一点。
当然,我很乐意被证明是错误的。
I have had this problem too but never been able to do anything about it. I usually end up using a full relative path and if the directory changes, well, I have to change it manually everytime. I see no other way to do this.
Of course, I would love to be proved wrong.
我认为您正在寻找的是 HTML
base
标签。在任何外部引用之前的
head
元素中指定
将使引用将http://mysubdomain.mysite.com/modules/admin/
作为路径根。要在整个站点中使用此功能,您可以编写一个小脚本并将其包含在母版页中。我还没有测试过,但我认为像下面这样的东西应该可以工作。 :
您可以在以下位置找到文档和教程: http://www.w3schools.com/tags/att_base_href .asp
I think what you are looking for is the HTML
base
tag.Specifying
<base href="http://mysubdomain.mysite.com/modules/admin/" />
in thehead
element prior to any external references will make the references takehttp://mysubdomain.mysite.com/modules/admin/
as the path root. To get this functionality throughout your site, you can write a little script and include it in your master page.I haven't tested it, but I think something like the following should would work. :
You can find documentation and a tutorial at: http://www.w3schools.com/tags/att_base_href.asp