Custom authentication in Asp.Net Core

ASP.NET Core does not have built-in membership for Active Directory. Developers can use Azure Active Directory or external membership services like Facebook and Linkedin or standard ASP.NET Identity mechanism, but are not able to use Active Directory directly. Visual Studio 2015 has removed Active Directory authentication from its web application template:



ASP.NET Core does not have web.config so old school ActiveDirectoryMembershipProvider does not help. ASP.NET Core use middleware mecahnism for handling requests. Settings cookies and checking it back in the server has been changed.


In order to do authentication in ASP.NET Core with Active Directory or any other resource like your own database back end you can take a look at following code.


This code must be put in Configure method of Startup class of the project. This tells application to use cookie for authentication. Every information is put in cookie, attached to response and sent back to the user. User attaches this cookie to all his/her requests and sent to the server again. This cookie is encrypted and contains Username, Role and other claims added by server code.



This code in used in sign in page. This is the place that you validate user entered credentials against a database or resource like Active Directory. For more information see here and here. Also I found a library for the whole process but was not successful to use it.

Leave a Reply

Your email address will not be published. Required fields are marked *