How these 2 paths are resolved in asp.net. why these 2 gives different path. At what time we need to go for these.
<link href="/common/black_theme/css/style.css" rel="stylesheet"> (this is working)
<link href="~/common/black_theme/css/style.css" rel="stylesheet"> (this is not working)
As per my knowledge ~ represents root directory of the application "Common" is the folder under root of the website(named testsite.demo) in IIS
physical path = D:\Physicalpath\WarpFirstSite\testsite.demo
common folder location - D:\Physicalpath\WarpFirstSite\testsite.demo\common
/
- Site root~/
- Root directory of the application
The difference is that if you site is:
http://example.com
And you have an application myapp
on:
http://example.com/mydir/myapp
/
will return the root of the site (http://example.com
),
~/
will return the root of the application (http://example.com/mydir/
).
The second won't work because its not a recognised path by anything except asp.net code on the server side. And since your link tag is regular html and not a server control it never gets processed.
If you add runat="server"
in your link tag then it would works perfectly....
like this....
<link href="~/common/black_theme/css/style.css" rel="stylesheet" runat="server">
(this is also working)
来源:https://stackoverflow.com/questions/6424114/slash-vs-tilde-slash-in-style-sheet-path-in-asp-net