asp.net - 无法在 Owin Startup.cs 中加载 System.Web.Cors

标签 asp.net azure oauth-2.0 cors owin

我有一个使用 Web API 2 并在本地 Azure 模拟器中运行的 .Net 4.5.1 应用程序。我安装了一些 OWIN 组件,并且在 Configuration(IAppBuilder app) 函数内的 Startup.cs 文件中,我有以下代码块,最后一行导致异常:

HttpConfiguration httpConfiguration = new HttpConfiguration();
WebApiConfig.Register(httpConfiguration);
app.UseWebApi(httpConfiguration);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

此行导致异常“无法加载文件或程序集“System.Web.Cors,Version=5.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。”

如果它是依赖项,我无法弄清楚为什么 NuGet 没有安装它。此外,我无法找到已安装的相应 dll 来添加引用,也无法找到正确的 NuGet 包来安装以提供所述 dll。

有人遇到过类似的问题吗?如果是这样,也许你可以为我指明正确的方向。

最佳答案

这肯定是因为您的 DLL 版本不同或该环境中缺少 DLL。

您需要检查的几个步骤:

  • Cors DLL 应该位于您的 BIN 目录中 [在 Azure 上]

  • 如果存在,那么服务器上部署的 DLL 版本和本地部署的 DLL 版本应该相同。 [您可以查看属性]

  • 如果您在 Azure 服务器上的 Cors DLL 版本较高,与本地版本进行比较,则可以
<dependentAssembly>
   <assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" />
   <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.1" />
</dependentAssembly>

您的新版本可能是您的 DLL 版本,可在 BIN 目录中找到。

关于asp.net - 无法在 Owin Startup.cs 中加载 System.Web.Cors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980010/

相关文章:

c# - 如何在没有调用堆栈的情况下获取异常消息

asp.net - 雪碧图像CSS

asp.net - 在 ASP 和 C# 中使用 RSS 提要

c# - 更改颜色并为链接按钮的内容添加下划线

c# - 如何使用 Send Grid mvc azure 通过 List<string>() 发送电子邮件

c# - 在 Azure 辅助角色中使用 kernel32 CreateThread/TerminateThread

c# - 无法从 Visual Studio 2017 调试和发布 Azure Function

php - Symfony2 中的 Oauth2

windows-8 - 如果从 foursquare 传递到 Facebook,WebAuthenticationBroker 将挂起

authentication - access_type = Online 什么时候合适? :OAuth2 - Google API