Reputation: 27526
I have an ASP.NET MVC 5 web application, using ASP.NET Identity 2.1. I'm trying to move all the identification / authorization code out of the web project into a class library.
I moved all the boilerplate UserManager
, SigninManager
stuff out, and removed all the NuGet packages for ASP.NET Identity and OWIN from the web project (adding those to the class library).
I also moved the code from the Startup.cs
and Startup.Auth.cs
files into my class library. These contain the OWIN configuration stuff.
How do I now ensure that this code is invoked when the application starts up? In the original project, the Startup
class (in Startup.cs
) had a line like this:
[assembly: OwinStartupAttribute(typeof(WebApplication1.Startup))]
I've put a similar line (with the correct class name) in the equivalent file in my class library, but that seems to have no effect. Does this line have to go in the web app? (I which case, presumably I'd need to add the OWIN NuGet package back into the web project - something I'd hoped to avoid).
I also tried adding this to my web.config file:
<add key="owin:appStartup" value="MyClassLibrary.MyNamespace.Startup, My.DLL.Name" />
But again, I'm not sure exactly how that would work without something within the web project triggering it - which again comes back to adding OWIN to the web project.
I'm so confused - any help would be appreciated.
Upvotes: 1
Views: 791
Reputation: 3725
From the http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx/
PreApplicationStartMethodAttribute
This new attribute allows you to have code run way early in the ASP.NET pipeline as an application starts up. I mean way early, even before Application_Start.
PreApplicationStartMethodAttribute is where Microsoft.Owin.Host.systemWeb gets initialised. Hence you need to add reference to Microsoft.Owin.Host.systemWeb in your web app.
Upvotes: 1