Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...