基本URL在ASP.net母版页与虚拟目录 [英] Base URL in ASP.net Master Pages with virtual Directories

查看:164
本文介绍了基本URL在ASP.net母版页与虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.net母版页。在这个主,我有我所有的CSS和JavaScript文件中定义。我也有一些图像和几个按钮和超链接。

所有网址都被宣布为相对的,即/scripts/ian.js

一切工作正常,如果这个网站是根网站,但我需要它在一个虚拟目录工作。

我的问题是,当我把这个网站的虚拟目录根站点下,我所有的链接都指向根网站。所以我的链接指向www.root.com/scripts/ian.js但应指向www.root.com/virtualDir/scripts/ian.js

我以为基本href 在标题标签会有所帮助,但到目前为止,似乎并没有无论如何要及时帮助。所有环节都仍然指向的网站的根,当我将鼠标悬停在他们。

我想是不是在IIS或者说我可以设置一个根URL,要么母版页或内容页面上的任何图片,文字或链接配置文件中的单个设置,将指向正确的地方。

任何建议或想法,欢迎。

感谢


解决方案

  

所有网址都被宣布为
  相对即/scripts/ian.js


这些似乎是绝对URL的您正在使用,而不是相对的URL,这大概就是为什么<底座/> 标记不具有预期效果:


  

该属性指定一个绝对的
  URI充当基本URI
  解析相对URI。


- 从<一个href=\"http://www.w3.org/TR/html401/struct/links.html#h-12.4\">http://www.w3.org/TR/html401/struct/links.html#h-12.4

您可以尝试除去最主要的'/'从你的URL,看看是否能工作?

如果做不到这一点,我倾向于使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveclienturl.aspx\">ResolveClientUrl要解决这个样子,你会以同样的方式使用问题,正如其他人使用建议的 RESOLVEURL 的:

 &LT;脚本类型=文/ JavaScript的SRC =&LT;%= ResolveClientUrl(〜/路径/要/ JS)%&GT;&GT;&LT; /脚本&GT;
...
&LT; IMG SRC =&LT;%= ResolveClientUrl(〜/路径/要/ IMG公司)%GT; ALT =.../&GT;

希望这有助于。

I have an ASP.net master page. In this master, I have all my css and javascript files defined. I also have a few images and a few buttons and hyperlinks.

All the urls are all declared as relative ie "/scripts/ian.js"

Everything works fine if this site is the root website, but I need it to work in a virtual directory.

My problem is when I place this website in a virtual directory under a root site, all my links are pointing to the root site. so my links point to www.root.com/scripts/ian.js but it should be pointing to www.root.com/virtualDir/scripts/ian.js

I thought the Base Href tag in the header would help, but so far it does not seem to be helping in anyway. All the links are still pointing to the root website when i hover over them.

What I would like is a single setting either in IIS or the config file that I can set a root url and any image, script or link either on the master page or content page, would point to the right place.

Any suggestions or ideas are welcome.

Thanks

解决方案

All the urls are all declared as relative ie "/scripts/ian.js"

Those seem to be absolute URL's that you're using, rather than relative URL's, which is probably why the <base /> tag isn't having the desired effect:

This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.

-- from http://www.w3.org/TR/html401/struct/links.html#h-12.4

You could try removing the leading '/' from your URL's to see if that works?

Failing that, I tend to use ResolveClientUrl to get around issues like this, which you'd use in the same way as others have suggested using ResolveUrl:

<script type="text/javascript" src="<%= ResolveClientUrl("~/path/to/js") %>"></script>
...
<img src="<%= ResolveClientUrl("~/path/to/img") %>" alt="..." />

Hope this helps.

这篇关于基本URL在ASP.net母版页与虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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