具有无扩展名 URL 的相对链接
我有一个实现 URL 路由的 ASP.NET 4.0 应用程序。这为我提供了没有扩展名的页面 URL(例如 /Articles/{title}),
其中一些页面包含相关链接。当我从 Visual Studio 测试网站时,相对链接指向 /Articles/{title}/mylink。但是,当我将网站部署到共享托管帐户时,相同的相对链接指向 /Articles/mylink。
您可以在 http://blackbeltcoder.com/Articles 查看该问题/asp/在-asp-net 中创建网站缩略图。顶部附近图像的链接已损坏。从 Visual Studio 进行测试时,此页面运行良好。 {title} 被假定为一个目录。但是,一旦部署,{title} 就被假定为页面名称。
如果我将“/”附加到上面的 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})
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.
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.
If I append "/" to the URL above, it works as expected. But how can I make sure it always works?
Can anyone help me understand this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在对该网站和另一个也使用 URL 路由的网站进行了大量测试后,我终于能够定义发生了什么。
我将把该网站在托管帐户上的行为方式描述为“正常”。这与我的其他网站在桌面上运行时在托管帐户和上的工作方式相同。 (尽管其他站点不以这种方式使用相对链接。)
奇怪的情况是当我在桌面上运行新站点时。浏览器会自动将“/”附加到我的路由 URL,就好像它们是目录一样。
这样做的原因是因为我创建了同名的物理目录!如果我删除物理目录,它会将 URL 视为对文件的引用。
所以对我来说主要的问题是我在测试这个奇怪的情况时开发了该网站。因此,解决方案是 A) 确保将“/”附加到所有这些链接,以便将它们视为目录,或者 B) 更改我设计的目录结构。
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.
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.
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.