ASP.NET Web API and System.Net.Http

Following the example in this article: http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help-page-using- apiexplorer.aspx

I configured everything to provide documentation for my web API project, but I had a problem. When I try to use @api.HttpMethod , I get an error that it describes about halfway through the article. He says that you need to manually add a reference to the System.Net.Http assembly, Version = 2.0.0.0 in the web.config file (although this is the default in the Links folder), but if you follow his example of adding an assembly, the path through the tag in web.config ..... well, you will find that it is no longer a valid tag in 4.5, and everything is done through AssemblyRedirects. I tried this, but to no avail. Anyone who has this problem or knows how to help with a change in web.config? Did I miss a meeting?

Visual Studio 2012 MVC4 Web API Project (not from Nuget, final release ships with VS2012)

+8
asp.net-mvc asp.net-web-api
source share
1 answer

Add the following configuration to the Web.config file in the <system.web> node section (assuming your application is running in .NET 4.5, the targetFramework attribute targetFramework set to 4.5):

 <compilation targetFramework="4.5"> <assemblies> <add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </assemblies> </compilation> 

Also add below one at the root level in the <configuration> node:

 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> 

This should solve your problem.

+22
source

All Articles