简体   繁体   English

带有目录的相对URL和绝对URL

[英]Relative and Absolute URLS with Directories

I'm just new to creating and launching web sites and i've hit a stumbling block. 我只是创建和启动网站的新手,遇到了绊脚石。

I have a hosting account with 3 different domains assigned to it. 我有一个托管帐户,并为其分配了3个不同的域。 Each domain is mapped to a section of the main directory. 每个域都映射到主目录的一部分。 So it goes like this: 所以它是这样的:

My Site - 
           -Site1
           -Site2
           -Site3

However i can't seem to use the same URLs which work locally on the hosted site and vice versa. 但是我似乎无法使用在托管站点上本地工作的相同URL,反之亦然。 This is an example of the code i use in a link: 这是我在链接中使用的代码示例:

<asp:MenuItem NavigateUrl="/Default.aspx" Text="Home"/>

This works fine when uploaded to the host, but locally i get an error: 当上传到主机时,这工作正常,但是在本地我得到一个错误:

HTTP Error 404 - Not Found. HTTP错误404-找不到。

And when i leave off the / 当我离开/

 <asp:MenuItem NavigateUrl="About.aspx" Text="About"/>

It will work locally but i will get an error when hosted: 它将在本地工作,但在托管时会出现错误:

Resource cannot be found: 找不到资源:
Requested URL: /Site1/Site1/About.aspx 要求的网址:/Site1/Site1/About.aspx

I've used ~, ../, default.aspx etc and it'll always work on one, but not the other. 我用过〜,.. /,default.aspx等,它将始终在其中一个上工作,而在另一个上不工作。 I'm sure im missing something dead simple but just can't work it out. 我敢肯定我错过了一些简单的东西,但无法解决。

Try this 尝试这个

<asp:MenuItem NavigateUrl="/ProgectName/About.aspx" Text="About"/>

Or ServerSide 或服务器端

Menu1.Items.Add(new MenuItem { NavigateUrl = Page.ResolveUrl("About.aspx"), Text = "About"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM