简体   繁体   English

带OWIN的MVC 4

[英]MVC 4 with OWIN

Breakdown : 细目

  • I created an empty MVC 4 project and proceeded to do the website. 创建了一个空的MVC 4项目 ,然后继续创建网站。
  • Realizing I need authorization and authentication in my project, I looked around and found OWIN to be my solution 意识到我需要在项目中进行授权和身份验证后,我环顾四周, 发现OWIN是我的解决方案
  • Tried to download OWIN packages through NuGet, but found that the targeting framework did not match . 试图通过NuGet下载OWIN软件包,但发现定位框架不匹配
  • OWIN said it needed a .NET framework of 4.5, which I'm currently at. OWIN表示,它需要一个我目前使用的4.5的.NET框架。
  • Confused, I still changed my project's .net to 4.6 , which helped me successfully download OWIN 感到困惑,我仍然将项目的.net更改为4.6 ,这帮助我成功下载了OWIN
  • Tried to run project, but gave me this error : 试图运行项目,但给了我这个错误

    "Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)" “无法加载文件或程序集'Newtonsoft.Json,版本= 4.5.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自HRESULT的异常:0x80131040 )”

    • So I changed my project back to 4.5, grudgingly uninstalled OWIN and tried to run the project, but the error still shows. 因此,我将项目更改回4.5,勉强卸载了OWIN,并尝试运行该项目,但错误仍然显示。

I'm at a loss with what to do now. 我不知道该怎么办。 I can't even run my project even after bringing 4.5 back. 即使恢复了4.5,我什至无法运行我的项目。 Can I keep trying to change my .NET framework version, or at this point, should I just install a lower version of OWIN? 我是否可以继续尝试更改.NET Framework版本,或者此时是否应该仅安装较低版本的OWIN? Thanks 谢谢

EDIT I have tried to reinstall newtonsoft in the package manager console through a code I found on here, which didnt work 编辑我试图通过我在这里找到的代码在软件包管理器控制台中重新安装newtonsoft,但没有用

Solved this problem by reverting my project back to .NET framework 4.5, and installing an older version of OWIN 通过将项目恢复为.NET Framework 4.5并安装较旧版本的OWIN解决了此问题

In the package manager console: 在包管理器控制台中:

Install-Package Microsoft.Owin.Host.SystemWeb -Version 2.1.0

then also add: 然后还添加:

<add key="owin:AutomaticAppStartup" value="false" />

to <appSettings> in Web.config file if errors about OwinStartupAttribute show up. 如果出现有关OwinStartupAttribute的错误,请转到Web.config文件中的<appSettings>

Apparently the main problem I had was because I was using VS2012, which is not supported by NuGet 2.12 , the version needed for the latest OWIN. 显然,我遇到的主要问题是因为我使用的是VS2012,而NuGet 2.12 (最新OWIN所需的版本) 不支持 VS2012。

Thanks to everyone's help 多亏大家的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM