in .net application have styleshet.css in css folder.
now want link css in sample.aspx.
what best approach
1.
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" /> or
2.
<link href="<%=configurationmanager.appsettings["applicationurl"].tostring()%>/css/stylesheet.css" rel="stylesheet" type="text/css" />
in web.config
<appsettings> <add key="applicationurl" value="http://localhost/myapp/" /> </appsettings>
the best way in asp.net option 3:
<link href="~/css/stylesheet.css" rel="stylesheet" type="text/css" />
the ~/
resolves site path root. difference between , "css/...
work no matter subfolder you're in. example if code in
/subsection/default.aspx
and styles in folder /css
using link "css/stylesheet.css"
resolve (incorrectly) "/subsection/css/stylesheet.css"
whereas using "~/css/stylesheet.css"
resolve (correctly) "/css/stylesheet.css"
this differs hard path root "/css/stylesheet.css"
in work correctly regardless of virtual directory configuration of site.
Comments
Post a Comment