我有一个angularJS应用程序。 我已经创建了一个控制器/动作,可以在任何请求中返回呈现的index.cshtml。 这是我唯一的mvc4控制器。 我使用webapi进行所有其他行为。 客户端应该只处理路由。 到目前为止运作良好。
RouteExistingFiles = false; routes.MapRoute( name: "Default", url: "{*url}", defaults: new { controller = "Index", action = "Index" } );问题是此解决方案匹配“localhost / favicon.ico,localhost / template.html”等资源。 我可以阻止或忽略这样的所有请求吗?
I've a angularJS application. I've created a controller/action that returns a rendered index.cshtml on any request. This is my only mvc4 controller. I use the webapi for all other behavior. The client-side should only handling the routes. Works well so far.
RouteExistingFiles = false; routes.MapRoute( name: "Default", url: "{*url}", defaults: new { controller = "Index", action = "Index" } );The problem is that this solution matches resources like "localhost/favicon.ico, localhost/template.html". Can i prevent or ignore all request like this ?
最满意答案
您可以使用IgnoreRoute以便路由模块忽略对这些资源的请求,例如:
routes.IgnoreRoute("favicon.ico"); routes.IgnoreRoute("{templateName}.html");必须在当前的Default路由之前添加这些。
You could use IgnoreRoute so the routing module ignores requests for those resources, for example:
routes.IgnoreRoute("favicon.ico"); routes.IgnoreRoute("{templateName}.html");These have to be added before your current Default route.
更多推荐
发布评论