gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:17:05 25 4
gpt4 key购买 nike

我有一个使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com