相对链接扩展名的网址 [英] Relative Links with Extension-less URLs

查看:122
本文介绍了相对链接扩展名的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 4.0应用程序实现URL路由。这给了我网页网址不带扩展名(例如/文章/ {}标题)

I have an ASP.NET 4.0 application that implements URL routing. This gives me page URLs with no extension (e.g. /Articles/{title})

有些网页包含相对链接。当我测试从Visual Studio的部位,相对链接指向/条/ {}标题/ myLink的。然而,当我部署我的网站到一个共享的托管帐户,相同的相对链接指向/文章/ myLink的。

Some of these pages contain relative links. When I test the site from Visual Studio, relative links point to /Articles/{title}/mylink. However, when I deploy my site to a shared hosting account, the same relative link points to /Articles/mylink.

您可以在 HTTP看到这个问题//blackbelt$c$cr.com/Articles/asp/creating-website-thumbnails-in-asp-net 。接近顶部到图像的链接断开。此页面从Visual Studio测试时工作得很好。 {标题}被假定为是一个目录。但是,一旦部署,{}标题被假定为页面名称。

You can see the problem at http://blackbeltcoder.com/Articles/asp/creating-website-thumbnails-in-asp-net. The link to an image near the top is broken. This page worked fine when testing from Visual Studio. {title} was assumed to be a directory. But, once deployed, {title} is assumed to be the page name.

如果我追加/的URL上面,它按预期工作。但是,我怎么能保证它始终工作?

If I append "/" to the URL above, it works as expected. But how can I make sure it always works?

谁能帮助我理解?

推荐答案

在与两个本网站和另外一个也使用URL路由广泛的测试,我终于能够确定发生了什么。

After extensive tests with both this website and another one that also uses URL routing, I'm finally able to define what is happening.

我要描述这个网站上的托管帐户为正常的行为方式。这是同样的方法我的其他网站的作品同时在托管帐户当我的桌面上运行。 (虽然其他站点不使用相对链接这种方式)。

I'm going to describe the way this site behaves on the hosting account as "normal". It's the same way my other site works on both the hosting account AND when run on my desktop. (Although the other site doesn't use relative links this way.)

这个奇怪的情况是出去的时候我跑我的桌面上的新网站。浏览器自动添加/我的路由的网址,就好像它们是目录。

The odd case out is when I run the new site on my desktop. The browser automatically appends "/" to my routed URLs, as though they are directories.

而它这样做的原因是因为我已经创建物理目录名称相同的!如果我删除的物理目录,它把URL作为一个文件的引用。

And the reason it does this is because I have created physical directories with the same names! If I delete the physical directory, it treats the URL as a reference to a file.

所以对我来说最主要的问题是,我开发的网站,而这种奇怪的情况下进行测试。因此,解决的办法是要么一)确保/附加到所有这些链接,使他们被认为是目录,或B)改变我设计的目录结构。

So the main problem for me is that I developed the site while testing with this odd case. Therefore, the solution is either A) make sure "/" is appended to all these links so they are considered directories, or B) alter the directory structure I've designed.

这篇关于相对链接扩展名的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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