Is there any way to use the ASP.NET Identity mechanism over two different projects?? ie. I want to use a single authentication mechanism for a MVC project and a WebAPI project. Is it possible?
Asked
Active
Viewed 1,042 times
4
-
1Sure it is; extract the Identity portion into its own project and use it in both projects. – Rik Apr 23 '15 at 16:25
1 Answers
0
There is nothing difficult about this. If using boiler-plate MVC 5 templates make sure both are referencing the Owin pipeline and are using the same authentication type/provider (usually in Startup.Auth.cs
).
If deploying to multiple web servers you will need to make sure your web.config's all share the same machineKey property.
An architecture I favour is to have a web project per user role.
For example
myproject.sln
— Auth.csproj (unauthorized)
— Profile.csproj (project has "AuthorizeAttribute" as default. All roles can access. Add filters.Add(new AuthorizeAttribute());
in FilterConfig.cs
)
— CustomRole.csproj (project has custom "MyCustomRoleAttribute" derived from AuthorizeAttribute added in similar way as above.)

Dan
- 968
- 1
- 8
- 21
-
Could you please clarify: 1. referencing the Owin pipeline (where should I look?) 2. using the same authentication type/provider (what does this look like in Startup.Auth.cs?) – Faizan Kazi Feb 25 '16 at 08:28