I'm playing with ASP.NET5/MVC6 and I built a small web application. When I use the IIS Express debug server of Visual Studio, everything is working as expected. But when I use the "web" server profile, meaning the WebListener server, then only my MVC Controllers and Views work. However, everything stored under "wwwroot" returns a 404. What I've put there are the CSS, JS and image files.
As soon as I switch back to IIS Express, the content is fetched properly.
The full source code is available there: https://github.com/acastaner/acastaner.fr-mvc6
This is my Startup class:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
This is my project.json file:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
"Microsoft.AspNet.Mvc": "6.0.0-beta3",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta3"
},
"frameworks": {
"aspnet50": { },
"aspnetcore50": { }
},
"bundleExclude": [
"node_modules",
"bower_components",
"**.kproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"commands": {
"web ": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
}
}
I'm using Razor for the views, here's a sample of how I reference the files:
<link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css">
Is there something obvious that I totally missed?
Edit:
I did try using @Url.Content("~/css/bootstrap.min.css")
but the effect is the same.
I think you need one more dependency: "Microsoft.AspNet.StaticFiles": "1.0.0-beta3"
and app.UseStaticFiles();
before app.UseMvc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With