asp.net and Visual studio root directory question
I am seeing something very odd and thought I would ask the Stackoverflow community if they knew the answer.
I have an asp.net project that runs fine in one environment, but couldn't figure out what happened to the styles in another environment.
In the first environment (Windows 2008 Server), the following link worked fine:
<link href="/Styles/09/style.css" rel="stylesheet" type="text/css" />
but in the other environment (it's a Windows 7), I had to change it to work:
<开发者_StackOverflowlink href="../Styles/09/style.css" rel="stylesheet" type="text/css" />
Notice that the directories seemed to shift ahead one directory in the Win7, what's going on? It's like the "running" directory seems now be the \bin directory instead of the home!
Which environment is configured correctly? How do I determine execution directory level? My concern going forward is pushing to a prod environment and guessing which configuration is correct.
Any insight would be appreciated!
The first way is going to search from the root path, the second goes up one directory first. My guess is on the first server your site was hosted at the root (www.example.com/), while on the second server it was hosted in a subdirectory (www.example.com/mysite/). In the second case, it would look at www.example.com/Styles instead of the intended www.example.com/mysite/Styles
../
is almost certainly wrong. That said, if you're having problems across environments the plain /
is probably wrong as well. Try using a '~' operator to set an accurate application root.
This link should help you figure out what exactly is going on:
http://msdn.microsoft.com/en-us/library/ms178116.aspx
../
is just wrong.
/
is site root. If running on webdev, this will be the root of your app. when you move your app to IIS it will be the root of the IIS site, e.g. http://localhost, not the root of your app, http://localhost/yourApp.
As Joel says, using '~' can help aleviate this problem, but the '~' only works on tags that get processed by the page. It isn't going to help you for paths in css or js nor the link tag presented unless you add runat=server .. I think. And even that is not going to help you with static resources like html.
Getting this worked out to provide consistent behavior between your dev and prod environment can be challenging but once you get it you got it.
are you sure that the hosting settings are correct.
I have had similar issues in the past when gettig ncode to work in IIS instead of the dev servers.
精彩评论