0

I was working on a migration job from Asp.net MVC4 beta to Asp.net MVC4, But I had a problem of dll reference missing. please help me .

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );


            routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
           );
        }

Above the code can't be compiled successfully, and Visual studio said System.Web.Routing.RouteCollection' does not contain a definition for 'MapHttpRoute' and no extension method 'MapHttpRoute' accepting a first argument of type 'System.Web.Routing.RouteCollection' could be found (are you missing a using directive or an assembly reference?)

More important thing is this kind of problem often happened.Because the version of the Asp.net MVC change so frequently in these days. and So did the version of Windows Azure Client ApI. It is very annoying problem.I hope someone can give some advise of How to deal with it. thanks.

3 Answers 3

3

I have solved it by adding a reference to System.Web.Http in RouteConfig.cs.

Sign up to request clarification or add additional context in comments.

Comments

3

I encountered this same problem but was unable to fix it by adding a reference to System.Web.Http. I still received the same error: System.Web.Routing.RouteCollection' does not contain a definition for 'MapHttpRoute'.

I believe this is occurring because in the latest version of MVC4, MapHttpRoute is no longer supported.

As it turned out, the function MapRoute is identical in parameter construction. If you replace MapHttpRoute with MapRoute, you should be able to compile your code and move onwards.

Comments

0

I solved this by adding a reference to System.Web.Mvc.Html and System.Web.Mvc in the web.config.

  <system.web>
    ...
    <httpRuntime targetFramework="4.5.2"/>
        <pages>
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Html" />
            </namespaces>
        </pages>
    ...
  </system.web>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.