当我在 Visual Studio 2012 中启动 Asp.net MVC4 网站时,我遇到了一个例外:
Could not load type 'System.Net.Http.Formatting.DefaultContentNegotiator'
from assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.
在代码上:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
整个代码看起来像:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Http;
namespace Accela.Apps.Diagnostics.Portal
{
public class RouteConfig
{
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 }
);
}
}
}
请帮我离开那里。谢谢。