简体   繁体   中英

Missing classes for Attribute Routing in Web API 2.0: Two different System.Web.Http 5.0.0.0 dll's?

Due to Web API 2's new features, I recently upgraded my MVC4 solution with Web API 1 to an MVC5 solution with Web Api 2. I followed these official upgrading steps and got my solution up and running.

However, when I try to use new features, I notice there's something wrong with my System.Web.Http (referenced from C:\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET Web Stack 5\\Packages\\Microsoft.AspNet.WebApi.Core.5.0.0\\lib\\net45\\System.Web.Http.dll). If I compare my 5.0.0.0 System.Web.Http dll with a DLL in a working Web API 2 solution downloaded from the internet, classes like ContinuationResult, FormattedContentResult, HttpVerbAttribute, NonActionAttribute, 4 Override..-snip-..Attributes, RouteAttribute

Looks like all new Web API 2 features are missing, though I use the right reference. How is this possible?

Looks like the Web Api 2.0 tutorial I was reading used a pre-release version of System.Web.HTTP. A silly search on the 'example-application-foldername' in Google brought me to this article on asp.net forum

The changeset on codeplex learns me that the classes I was missing were removed after refactoring. Some changes were made after the Release Candidate , in short: since v5.0 went in RTM you should use Attribute Routing like this:

[Route("actors/{actorId}/movies")] // Web API 2.0 Official release

Instead of this:

[HttpGet("actors/{actorId}/movies")] //Web API 2.0 prerelease 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM