c# - Javascript and CSS files don't work when using a sub-directory -
i need base path because application hosted sub-site like:
www.example.com/site1/site2/ where iis application setup in site2, razor pages , master page referencing things like:
<link href="/assets/css/styles.css" rel="stylesheet"> when in case should like:
<link href="/site1/site2/assets/css/styles.css" rel="stylesheet"> i have images like:
<img src="/assets/images/logo.jpg" /> how can work in dynamic way don't have hard code sub-directory somewhere?
you should use built in helpers relative path content.
<link href="@url.content("~/assets/css/styles.css")" rel="stylesheet"> for site hosted @ www.domain.com/site/subdirectory, above render out
<link href="/site/subdirectory/assets/css/styles.css" rel="stylesheet"> and, if ever move site or change root path, not have change markup code.
more examples:
images
<img src="@url.content("~/assets/images/logo.jpg")" /> javascript
<script type="text/javascript" src="@url.content("~/assets/scripts/jsfile.js")"></script>
Comments
Post a Comment