问题
IIS 6 ASP.NET 3.5 (C#.NET)
We are having an issue where the same set of files behave differently depending on if it is a root IIS website versus an application under an IIS website. The urls produced using ResolveUrl() are different - i.e.:
<a href="<%=ResolveUrl("~/contact.aspx") %>">Contact Us</a>
- As the root website, it produces: http://contact.aspx
- As an application under a website, it produces: http://domainname.org/DSC/contact.aspx
Both are utilizing the same files. The first example is its own website, the second is a virtual directory made into an application (titled DSC). Both also use the same application pool, and same configuration, document and security settings (I made sure all the settings were the same in IIS between both).
Everything that has been researched indicates ResolveUrl() does refer to the IIS application that the webpage is under. I have also read several places that even if the information isnt completed in IIS (in this case it is), a root website is considered an application. Therefore, it should produce the appropriate web address, but isnt.
Any help in finding more research to determine what settings/configuration is not set appropriately, or why ResolveUrl() is not what should be used programmatically.
回答1:
Check this out: From Relative Path to Absolute Path in ASP.NET without using the Tilde ~. You might consider replacing your tilde (~) usage with HttpRuntime.AppDomainAppVirtualPath
. If the web application is in a server root folder, AppDomainAppVirtualPath
returns just "/". If web application is in a non-root folder it returns virtual path of the folder without "/" in the end (source).
来源:https://stackoverflow.com/questions/5239226/iis-6-website-root-vs-application-resolveurl