2012年5月16日 星期三

Visual Studio Debug Web Server

I've been asked to create a web interface structure for a site still being planned. I guess my supervisor only expect me to make an outer shell to encase whatever he is developing. So I've been making webpages in VS2008. In the process I realized that when I open the pages with browsers from the debug mode, a lot of redirections end up with page 404. I searched online for some answers, but didn't find any. I guess other developers are smart enough to find out what the problem was.

Well, after delving into this problem for a while, I realize how stupid i was. The url displayed in the browser when I redirect from the default page to other pages I made was wrong. It somehow included the folder them that I place my file.

Normally, if I save my site in a folder called MySite. When I host this up, I expect that http://localhost would point to MySite. And indeed the default page would work. But clicking on links to other pages would result in http://localhost/MySite/xxx.html while http://localhost/xxx.html is correct url. Why?

After looking through some settings, I realized that VS2008 automatically set the virtual path of the site to "/MySite/", which make all the virtual paths to automatically include "MySite/" when it shouldn't, causing the annoying page 404. Note that this only happens when you run with visual studio's developer server. When you host the files on IIS, it does not get affected. So I think it's a setting only for the developer server program.

Fix: In the solution explorer, select your site (usually the very top item with the full path to the working folder). Then in the Properties panel, under Developer Web Server, change the virtual path from whatever to "/" (usually you just need to delete the folder name portion). Then you should find the developer server working properly.

沒有留言:

張貼留言