找不到方法:"System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()" [英] Method not found: 'System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()'
问题描述
我已经创建了一个过滤器属性
I have created One Filter Attribute
public class AuthFilterAttribute : System.Web.Http.Filters.ActionFilterAttribute
{
public AuthFilterAttribute()
{
}
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
}
}
我已经在global.asax.cs
中注册了此过滤器.
I have registered this filter inside the global.asax.cs
.
当我尝试使用 Postman 调用我的Web API时,显示错误:
When I am trying to call my web API using Postman it is showing the error:
找不到方法:"System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()".
Method not found: 'System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()'.
我的项目目标框架是4.6.1
,而System.Net.Http
版本是4.2.0.0
My project target framework is 4.6.1
and the System.Net.Http
version is 4.2.0.0
我的API如下:
[AuthFilter]
public class ScheduleApiController : BaseApiController
{
[Route("api/v1/schedules")]
[HttpGet]
public IHttpActionResult GetSchedules()
{
}
}
我知道之前曾有人问过这个问题,但是没有一个解决方案对我有用.
I know this question has been asked before but none of the solutions worked for me.
请帮助我解决此问题.
推荐答案
您是否偶然引用.NET标准库.我遇到了这个问题,并通过绑定重定向解决了这个问题:
Are you referencing a .NET Standard Library by any chance. I ran into this problem and solved it with a Binding Redirect:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
这篇关于找不到方法:"System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!