Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法加载文件或程序集';System.Web.Http.Owin';_C#_.net_Asp.net Web Api_Owin - Fatal编程技术网

C# 无法加载文件或程序集';System.Web.Http.Owin';

C# 无法加载文件或程序集';System.Web.Http.Owin';,c#,.net,asp.net-web-api,owin,C#,.net,Asp.net Web Api,Owin,我升级了MVC5和WebAPI 2.2,创建了MVCWeb应用程序。在它里面,我为我的主项目添加了定义为子项目的空Web API,我只想保护我的数据, 路由运行良好。但我想从我的上下文中获取一些数据, 当尝试进入localhost:34862/api/account/test时,我得到一个错误 这是我的ApiController中的代码 [RoutePrefix("api/account")] public class AccountController : ApiController {

我升级了MVC5和WebAPI 2.2,创建了MVCWeb应用程序。在它里面,我为我的主项目添加了定义为子项目的空Web API,我只想保护我的数据, 路由运行良好。但我想从我的上下文中获取一些数据, 当尝试进入localhost:34862/api/account/test时,我得到一个错误

这是我的ApiController中的代码

[RoutePrefix("api/account")]
public class AccountController : ApiController
{
    private readonly IAccountUoW _iaUoW;

    public AccountController(IAccountUoW iaUoW)
    {
        _iaUoW = iaUoW;
    }

    [Route("")]
    [HttpGet]
    public string Get()
    {
        return "test";
    }

    [Authorize]
    [Route("test")]
    [HttpGet]
    public async Task<IHttpActionResult> GetTourInfos()
    {
        var ctx = (OwinContext)Request.GetOwinContext();
        ClaimsPrincipal user = ctx.Authentication.User;
        IEnumerable<Claim> claims = user.Claims;
        return Ok();
    }
}
[RoutePrefix(“api/账户”)]
公共类AccountController:ApicController
{
私人只读IAccountUoW;
公共账户控制员(IAccountUoW iaUoW)
{
_iaUoW=iaUoW;
}
[路线(“”)
[HttpGet]
公共字符串Get()
{
返回“测试”;
}
[授权]
[路线(“测试”)]
[HttpGet]
公共异步任务GetTourInfos()
{
var ctx=(OwinContext)Request.GetOwinContext();
ClaimsPrincipal user=ctx.Authentication.user;
IEnumerable claims=user.claims;
返回Ok();
}
}
我从NuGet添加的推荐信

  • Microsoft ASP.NET Web API 2.2
  • 奥温
  • Microsoft.Owin
  • Microsoft.Owin.Host.SystemWeb
  • Microsoft.Owin.Security.Cookies
  • Microsoft.Owin.Security.OAuth
我还检查了我从主项目添加到子项目的引用,它有相同的版本 从我的子项目

此处为子项目的packages.config



问题可能是Web Api 2.2使用microsoft.owin 2.0.2版本。您可以在web.config中更改行为

如果您的microsoft.owin版本为3.0.0,请在“bindingRedirect”行的“newVersion”中设置为3.0.0

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>


关于,

tnx再次评论,很抱歉,我忘了只在主项目和子项目上添加相同的引用,例如,如果在子项目上添加Microsoft.AspNet.WebApi.WebHost,则还必须使用相同的引用和版本添加到主项目。否则将无法加载引用,否则将出现错误。