2015-01-03 106 views
1

我使用vnext并使用路由,但它路由所有。asp vnext,忽略路由

这是(来自Startup.cs)细:

application.UseMvc(routes => 
      { 
       // setup routes 
       // default mapping 
       routes.MapRoute(
        name: "default", 
        template: "{controller}/{action}/{id?}", 
        defaults: new { controller = "Home", action = "Index" }); 
       }); 

但然后当我使用(在视图中)

<link href='@Url.Content("~/CDN/r.css")' rel="stylesheet" /> 

<img src="/CDN/i.png" /> 

它给出了一个404错误在那些。

那么如何设置忽略路线,如在以前的版本?

日Thnx

回答

1

你应该MVC之前注册StaticFiles中间件为你的情况,你想为像.css.png等静态文件,以便对静态文件的请求将通过这个中间件提供服务,不会达到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?}"); 
       }); 

您需要在project.json中添加包Microsoft.AspNet.StaticFiles才能得到它。

+0

仍然相同。 404.!?我添加了nuget,我添加了usestatic文件,并且css和png文件仍然以404结果。 – b0x0rz

+1

您是否已将'CDN'文件夹放在'wwwroot'文件夹下?静态文件应该放在'wwwroot'文件夹下。 –

+0

是的。就是这样。 thnx一个可以帮助我坚持并帮助我的LOT <3一直缺席,但现在就尝试了,它确实能够解决问题。将编辑答案并接受。 – b0x0rz