Question

I've this little but annoying issue in my project in Visual Web Developer 2010 Express. I'm developing a website with .aspx files located in a large folder structure i.e. www.domain.com/group1/type1/somefile.aspx, the root folder contains a "styles" (for css), "images" and "js" (for javascripts) folder. I've read a lot about base tag, absolute and relative path today. Finally I realized "absolute path" is the best choice for me.

The main problem is that when I preview (locally) my site in browser the absolute links for image, css, and js are not working, I'm using src="/js/gl.jquery.js" which I believe is correct and will work online.

The source code of the page for the javascript says http://localhost:61700/js/gl.jquery.js, when I switch to relative path script src="../../../js/gl.jquery.js" and preview the website, it works fine, and the source code for the javascript path says http://localhost:61700/ProjectName/js/gl.jquery.js (Notice Visual Studio added the ProjectName in the path) So I'm taking my guess that when the project goes online (on a main domain) it will work correctly, but right now I need to keep developing locally without this issue. Is there a way to fix this in Visual Web Developer? maybe some tag for the web.config file that I can remove when goes online, or some website property?

I know a quick solution will be develop with the relative path, and modify the code when goes online to absolute path, but I'm looking for some cleaner method, as aditional information I didn't choose base tag because I read cause troubles with anchors links (href=xx.html#question3) and I need to use them at some big files. And avoid the relative path because it's possible that the company ask me to move some files in the future and I don't wanna be updating relative paths.

Thanks a Lot!

Was it helpful?

Solution

Problem solved! This is the solution I found Thanks to ScottGu's Blog.

I quote the main thing: when opened a web-site and run the project, VWD launch and run the built-in web-server using a virtual app path that equals the project’s root directory name. For example: if you have a project named “Foo”, it will launch and run in the built-in web-server as http://localhost:1234/Foo/Default.aspx. One downside to this is that it makes it hard to fully qualify things like static CSS and image files within your site (for example: using root qualified paths like /images/myphoto.jpg or /css/mycss.css). Note that you can use the “~” app path trick for dynamic resources – but static resources still end up being a pain (js, css, images files.) (This was my issue)

Here is the guy entire post: Click Here

Here is the main solution:

1) Using the solution explorer within Visual Studio, select the web-site project node, (the one with the World icon)

2) There is a properties named "Virtual path" at the bottom. Change the "virtual path" setting it to / to run as a root web-site.

And that's it, setting up the / I can manage my files easily.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top