Reputation: 3981
i am using vnext and am using routes, but it routes EVERYTHING.
this is fine (from Startup.cs):
application.UseMvc(routes =>
{
// setup routes
// default mapping
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
but then when i use (in views)
<link href='@Url.Content("~/CDN/r.css")' rel="stylesheet" />
or
<img src="/CDN/i.png" />
it gives a 404 error on those.
so how to set up ignore routes as in the previous versions?
thnx
Upvotes: 1
Views: 944
Reputation: 57949
You should register a StaticFiles
middleware before MVC for your case where you want to serve static files like .css
, .png
etc. So the request for static files would be served by this middleware and would not reach MVC.
// Add static files to the request pipeline.
app.UseStaticFiles();
application.UseMvc(routes =>
{
// setup routes
// default mapping
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
You would need to add the package Microsoft.AspNet.StaticFiles
in project.json to get it.
Upvotes: 1