简体   繁体   English

没有Owin的Asp.Net MVC 5?

[英]Asp.Net MVC 5 without Owin?

Mvc 5 seems to depend on Owin, which is great if you want to self host or run on a Mac. Mvc 5似乎依赖于Owin,如果你想自己托管或在Mac上运行,那就太棒了。 But lets assume I just want to run under IIS just like the previous versions and I'm not interested in what Owin has to offer. 但是我们假设我只想在IIS下运行,就像以前的版本一样,我对Owin提供的东西不感兴趣。 The default "blank" mvc5 template uses owin and 15 other dependencies. 默认的“空白”mvc5模板使用owin和其他15个依赖项。 I've tried removing packages one by one but it seems like the site didn't know how to start without using an attribute from Owin. 我已经尝试逐个删除软件包,但似乎网站不知道如何在不使用Owin的属性的情况下启动。 So, how do I get just ASP.net, mvc 5, under iis without Owin? 那么,如何在没有Owin的iis下获得ASP.net,mvc 5?

The easy way to disable Owin is in web.config file and in <appSettings> section add this: 禁用Owin的简单方法是在web.config文件中,在<appSettings>部分添加:

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

To remove Owin completely right click on your project and from menu click on Manage Nuget Packages . 要完全删除Owin,请右键单击您的项目,然后从菜单中单击Manage Nuget Packages on left side of Manage Nuget Packages window click on Installed Package then on right side of window in search box type owin . 在左侧Manage Nuget Packages的窗口中点击Installed Package ,然后在窗口的右侧搜索框中键入owin

在此输入图像描述 uninstall packages in order of: 按以下顺序卸载软件包:

  • microsoft.aspnet.identity.owin microsoft.aspnet.identity.owin
  • microsoft.owin.host.systemweb microsoft.owin.host.systemweb
  • microsoft.owin.security.cookies microsoft.owin.security.cookies
  • microsoft.owin.security.facebook microsoft.owin.security.facebook
  • microsoft.owin.security.google microsoft.owin.security.google
  • microsoft.owin.security.microsoftaccount microsoft.owin.security.microsoftaccount
  • microsoft.owin.security.twitter microsoft.owin.security.twitter

and after removing microsoft.owin.security.twitter other owin packages removed automatically and if it does not happened on your machine remove the others by yourself. 删除microsoft.owin.security.twitter后自动删除其他owin软件包,如果您的机器上没有发生,请自行删除其他软件包。 then remove this packages: 然后删除此包:

  • microsoft.aspnet.identity.entityframework microsoft.aspnet.identity.entityframework
  • microsoft.aspnet.identity.core microsoft.aspnet.identity.core

Open web.config file and remove these sections from <runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> : 打开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>

Remove Startup.cs file in root of the project. 删除项目根目录中的Startup.cs文件。 open App_Start folder and remove IdentityConfig.cs and Startup.Auth.cs files. 打开App_Start folder并删除IdentityConfig.csStartup.Auth.cs文件。 open Controller folder and remove AccountController.cs and ManageController.cs . 打开Controller folder并删除AccountController.csManageController.cs in Models folder Delete all Models and in View Folder Remove Account Folder and Manage folder . Models folder删除所有模型并在View Folder删除Account FolderManage folder

Restarts Visual Studio and after that run the project. 重新启动Visual Studio,然后运行该项目。 if you get this error: 如果你收到这个错误:

The following errors occurred while attempting to load the app. 尝试加载应用程序时发生以下错误。 - No assembly found containing an OwinStartupAttribute. - 找不到包含OwinStartupAttribute的程序集。 - No assembly found containing a Startup or [AssemblyName].Startup class. - 找不到包含Startup或[AssemblyName] .Startup类的程序集。 To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config. 要禁用OWIN启动发现,请在web.config中添加值为“false”的appSetting owin:AutomaticAppStartup。 To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config. 要指定OWIN启动程序集,类或方法,请在web.config中添加appSetting owin:AppStartup以及完全限定的启动类或配置方法名称。 you have two ways to solve it: 你有两种解决方法:

  1. Open bin folder and if there is any Owin assembly , delete all of them 打开bin folder ,如果有任何Owin assembly ,则删除所有这些bin folder
  2. Or open web.config in <appSettings> section then add this <add key="owin:AutomaticAppStartup" value="false" /> 或者在<appSettings>部分打开web.config然后添加此<add key="owin:AutomaticAppStartup" value="false" />

The default mvc5 template uses Identity as the membership system. 默认的mvc5模板使用Identity作为成员资格系统。 Identity depends on Owin so that's the reason it's included in the project (with several other 'optional' packages). 身份取决于Owin,这就是它被包含在项目中的原因(以及其他几个“可选”包)。 If you create a new empty project and install manually the package Microsoft.Aspnet.Mvc (with the command Install-Package Microsoft.Aspnet.Mvc ) you can see there's no dependency on Owin. 如果您创建一个新的空项目并手动安装包Microsoft.Aspnet.Mvc(使用命令Install-Package Microsoft.Aspnet.Mvc ),您可以看到没有依赖于Owin。

Obs: You could also create an Empty project with 'Add folders and core references for MVC' option checked. Obs:您还可以创建一个空项目,其中选中了“为MVC添加文件夹和核心参考”选项。

OWIN只是一个标准,它将ASP.net应用程序与IIS分离,因此应用程序可以自托管,以及其他好处,但它并不意味着您无法在IIS中托管它们。

I just specify the complete route and it works for me!! 我只是指定完整的路线,它适合我!

Project name: Users.Web
Folders: App_Start
Class name: IdentityConfig

<add key="owin:AppStartup" value="Users.Web.App_Start.IdentityConfig" />

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

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