禁用 Owin 的简单方法是在 web.config 文件和 <appSettings> 部分添加:
<add key="owin:AutomaticAppStartup" value="false" />
要完全删除 Owin,请右键单击您的项目,然后从菜单中单击 Manage Nuget Packages。在Manage Nuget Packages 窗口的左侧单击Installed Package,然后在窗口右侧的搜索框中键入owin。
按以下顺序卸载软件包:
- microsoft.aspnet.identity.owin
- microsoft.owin.host.systemweb
- microsoft.owin.security.cookies
- microsoft.owin.security.facebook
- microsoft.owin.security.google
- microsoft.owin.security.microsoftaccount
- microsoft.owin.security.twitter
并在删除microsoft.owin.security.twitter 后自动删除其他 owin 包,如果它没有在您的机器上发生,请自行删除其他包。
然后删除这个包:
- microsoft.aspnet.identity.entityframework
- microsoft.aspnet.identity.core
打开web.config 文件并从<runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 中删除这些部分:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
删除项目根目录中的Startup.cs 文件。打开 App_Start folder 并删除 IdentityConfig.cs 和 Startup.Auth.cs 文件。打开Controller folder 并删除AccountController.cs 和ManageController.cs。在Models folder 中删除所有模型并在View Folder 中删除Account Folder 和Manage folder。
重新启动 Visual Studio,然后运行项目。如果您收到此错误:
尝试加载应用时出现以下错误。
- 未找到包含 OwinStartupAttribute 的程序集。
- 未找到包含 Startup 或 [AssemblyName].Startup 类的程序集。要禁用 OWIN 启动发现,请添加 appSetting
owin:AutomaticAppStartup 在 web.config 中的值为“false”。
要指定 OWIN 启动程序集、类或方法,请添加
appSetting owin:AppStartup 具有完全限定的启动类或
web.config 中的配置方法名称。
你有两种方法来解决它:
- 打开
bin folder,如果有Owin assembly,全部删除
- 或者在
<appSettings> 部分打开web.config 然后添加这个<add key="owin:AutomaticAppStartup" value="false" />