23

Mvc 5 seems to depend on Owin, which is great if you want to self host or run on a 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. The default "blank" mvc5 template uses owin and 15 other dependencies. 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. So, how do I get just ASP.net, mvc 5, under iis without Owin?

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
Andy
  • 8,432
  • 6
  • 38
  • 76
  • Your question amounts to "How do I run Asp.Net MVC 5 without the Asp.Net vNext framework". – Aron Jul 28 '15 at 04:12
  • 4
    @Aron Unless Owin is now an integral part of Asp.Net and cannot be used without it, no, that's not my question. – Andy Jul 28 '15 at 12:23

4 Answers4

46

The easy way to disable Owin is in web.config file and in <appSettings> section add this:

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

To remove Owin completely right click on your project and from menu click on 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.

enter image description here uninstall packages in order of:

  • 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

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. then remove this packages:

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

Open web.config file and remove these sections from <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. open App_Start folder and remove IdentityConfig.cs and Startup.Auth.cs files. open Controller folder and remove AccountController.cs and ManageController.cs. in Models folder Delete all Models and in View Folder Remove Account Folder and Manage folder.

Restarts Visual Studio and after that run the project. if you get this error:

The following errors occurred while attempting to load the app. - No assembly found containing an OwinStartupAttribute. - No assembly found containing a Startup or [AssemblyName].Startup class. To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config. 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. you have two ways to solve it:

  1. Open bin folder and if there is any Owin assembly, delete all of them
  2. Or open web.config in <appSettings> section then add this <add key="owin:AutomaticAppStartup" value="false" />
Mohsen Esmailpour
  • 11,224
  • 3
  • 45
  • 66
4

The default mvc5 template uses Identity as the membership system. Identity depends on Owin so that's the reason it's included in the project (with several other 'optional' packages). 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.

Obs: You could also create an Empty project with 'Add folders and core references for MVC' option checked.

Rafael Companhoni
  • 1,780
  • 1
  • 15
  • 31
1

OWIN is just a standard, which decouples ASP.net apps from IIS, thus apps can be self hosted, among other benefits, but it doesnt mean that you cant host them in IIS.

ryudice
  • 36,476
  • 32
  • 115
  • 163
  • 2
    I know that, but I don't want all the dependencies that brings, hence my question (which this doesn't answer). – Andy Jul 27 '15 at 23:51
  • @Andy What dependencies are you wanting to remove. Part of the point of vNext is that the framework is brought in via nuget. Are you trying to remove asp.net? http://www.hanselman.com/blog/IntroducingASPNETVNext.aspx – Aron Jul 28 '15 at 04:08
  • @Aron No, I'm not trying to remove Asp.Net, just Owin. – Andy Jul 28 '15 at 12:15
  • Saying "owin is just a standard" is ignoring a whole lot of extension methods that are built up on the standard that you need to use to configure things. – Greg May 20 '19 at 20:31
-1

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" />
Liam
  • 27,717
  • 28
  • 128
  • 190