I am trying to make only static files accessible which are in the wwwroot subfolder of my .NET 4.x project, following the accepted answer from Map to wwwroot in ASP.Net 4?
This means that the MVC script Scripts/LoginPage/app.js
will no longer be accessible at all, while wwwroot/Scripts/LoginPage/app.js
will be accessible through http://localhost:8080/Scripts/LoginPage/app.js
.
However, the project has MVC pages with Bundles, and I am now trying to configure the bundles correctly. The old bundle config is like this:
bundles.Add(
new ScriptBundle("~/Bundles/Scripts/loginpages/index").Include(
"~/Scripts/LoginPage/application.js",
"~/Scripts/LoginPage/index.js"));
The MVC page is rendering the bundle like this:
@Scripts.Render("~/Bundles/Scripts/loginpages/index")
If I just keep everything as is, the page contains the unbundled scripts as follows:
<script src="/Scripts/LoginPage/application.js"></script> <script src="/Scripts/LoginPage/index.js"></script>
but the files themselves are not accessible.
If I move the scripts but keep the bundle config unchanged, scripts are not included in the HTML at all.
If I move the scripts into the wwwroot subfolder, and change my bundles to reference the scripts in that subfolder:
bundles.Add( new ScriptBundle("~/Bundles/Scripts/loginpages/index").Include( "~/wwwroot/Scripts/LoginPage/application.js", "~/wwwroot/Scripts/LoginPage/index.js"));
then in the debug version this yields the following result HTML:
<script src="/wwwroot/Scripts/LoginPage/application.js"></script> <script src="/wwwroot/Scripts/LoginPage/index.js"></script>
but the content of the wwwroot folder (which includes the unbundled scripts) will be available at
/
, not/wwwroot/
, thus the files are not found.
How can I configure my scripts/bundles correctly?