简体   繁体   中英

Relative Links with Extension-less URLs

I have an ASP.NET 4.0 application that implements URL routing. This gives me page URLs with no extension (eg /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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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