visual studio debugging - url includes foldername - breaking my code
When I right click on ASP.NET development server, it says http://localhost:1394/testing as the ROOT URL. This does not go well with my code. I think the main reason is my code assumes it is in the root folder, and things start breaking when that is not the case. If I deploy this website, then it all works, but I lose my debugging capabilities. Is there a way I can make it skip the name of the folder (which is "testing" in this case)?
I am using virtual URL. Things break on virtual urls, not on static ones. (But virtual url works fine when deployed, and make sure it is in the root folder, otherwise it will not work.)
Here are t开发者_开发知识库he issues I am facing on virtual url's. Images are broken, if I right click on them, it lists the url without the folder-name http://localhost:1394/images/xyz.jpg instead of http://localhost:1394/testing/images/xyz.jpg. If I click on an asp:button, it postbacks to http://localhost:1394/storecategory/virtualcategory.aspx instead of http://localhost:1394/testing/storecategory/virtualcategory.aspx. So, you see it is eating up testing from the url, so I wanted to see if there is a way I can make http://localhost:1394/ as the url instead of http://localhost:1394/testing/.
Please let me know if this is confusing.
Yes.
If you are building a Web Site project, click on the application name in the Solution Explorer, and then in the Properties pane find the "Virtual Path" property. Remove the folder name, leaving just the /
.
If you are building a Web Application project, go to Properties | [Project Name] Properties... open the "Web" pane, and ensure that the "Virtual Path" value is set to /
.
You shouldn't use fully qualified addresses within our aspx files when referencing the local (same) site. You should use "~/", which is relative to the site root. So if the page you want to reference is test.aspx in site sub-folder orders, you would use this string as the link: "~/orders/test.aspx"
. This is true in both code-behind and directly on the aspx page definition; the ASP.NET engine will take care of converting that address to the correct address based on the site or virtual server your site has been installed into.
For example, on your dev system if your root is http://localhost:1394/testing and on your production system root is http://company.com then the respective URLs generated from the same relative string will be http://localhost:1394/testing/orders/test.aspx and http://company.com/orders/test.aspx.
精彩评论