问题
I just had to downgrade my ASP.Net 4.5.2 application to ASP.Net 4.0. Of course this brings problems with it, like references that are not installed correct. I solved some of them already, but I can't get my head around an error:
CS106 'RouteCollection' does not contain a definition for 'MapMvcAttributeRoutes' and no extension method 'MapMvcAttributeRoutes' accepting a first argument of type 'RouteCollection' could be found
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "device", action = "view", id = UrlParameter.Optional });
}
}
Does someone know what I have to do here?
Extra info
Namespaces that I use:
- using System.Web
- using System.Web.Mvc
- using System.Web.Routing
- using System.Web.Http
Visual studio Community 2015
回答1:
The only version of MVC that supports attribute routing (which provides support for the MapMvcAttributeRoutes
extension method) is MVC 5.
However, MVC 5 only supports .NET framework 4.5 and higher.
So, you have 2 options:
- Stay on .NET Framework 4.5+
- Downgrade to MVC 4 and either:
- Ditch attribute routing altogether and use convention-based routing
- Go with the open source attribute routing that supported MVC 3 and 4
Being that Microsoft officially no longer supports any version of .NET Framework lower than 4.5.2 (except for 3.5, but that would mean downgrading to MVC 2 for support), I would highly recommend you consider the first option seriously.
回答2:
I used routes.Ignore(). It seems to be working.
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes) {
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "device", action = "view", id = UrlParameter.Optional });
}
}
来源:https://stackoverflow.com/questions/37991768/routecollection-doesnt-contain-a-definition-for-mapmvcattributeroutes