'Module zero' is the first module for ASP.NET Boilerplate that includes following features:
- Implements ASP.NET Identity framework for User and Role management.
- Provides a Role and Permission based authorization system.
- Provides infrastructure to develop multi-tenant applications.
- Implements Setting system of ASP.NET Boilerplate to store Tenant, Application and User level settings in the database.
- And much more...
IMPORTANT NOTE: This project is not production ready yet and not released. But, if you want to try early, you can follow the instructions below:
-
Create ABP based project. You must have an existing ASP.NET Boilerplate based solution. If not, you can create one on http://www.aspnetboilerplate.com/Templates EntityFramework support for this module is not ready yet, choice NHibernate.
-
Install nuget packages. I assume that your application's name is MyAbpApplication and your projects in solution are: MyAbpApplication.Core MyAbpApplication.Application MyAbpApplication.Infrastructure.NHibernate MyAbpApplication.WebApi MyAbpApplication.Web Then install nuget package Abp.Zero for Core and Web projects, Abp.Zero.NHibernate for Infrastructure.NHibernate project.
-
Define module dependencies (See http://www.aspnetboilerplate.com/Pages/Documents/Module-System#DocModuleDepend for documents). Add AbpZeroModule dependency to your core module (MyAbpApplicationCoreModule class in MyAbpApplication.Core assembly) Add AbpZeroNHibernateModule dependency to your MyAbpApplicationDataModule class.
-
Create database tables. Use FluentMigrator migrations. Download AbpZeroDbMigrations.zip on https://github.com/aspnetboilerplate/module-zero/tree/master/temp, extract zip file, open RunMigrations.bat file, change connection string and run the bat file.
-
Install Identity framework and owin nuget packages. Add Microsoft.Owin.Host.SystemWeb and Microsoft.AspNet.Identity.Owin packages to your web project.
-
Create Owin Startup class. It will be something like that:
[assembly: OwinStartup(typeof(Startup))]
namespace MyAbpApplication.Web
{
public class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void Configuration(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
}
}
- Use Identity framework in your controller to log in.
private void Login()
{
//Surely, this informations should be sent from clients
const string userName = "admin";
const string password = "123qwe";
const bool rememberMe = true;
//Find the user
var user = _userManager.FindByName(userName);
//Check password
if (!_userManager.CheckPassword(user, password))
{
throw new UserFriendlyException("User name or password is invalid");
}
//Create identity
var identity = _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie).Result;
//Sign in
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity);
}
Instead of manual installation, for a running sample application:
- Create database tables. Download AbpZeroDbMigrations.zip on https://github.com/aspnetboilerplate/module-zero/tree/master/temp, extract zip file and run the bat file.
- Download MyAbpApplicationWithModuleZero.zip on https://github.com/aspnetboilerplate/module-zero/tree/master/temp, extract zip file, open and run the solution on Visual Studio.
- Read ASP.NET Identity Framework's documentation for more information on ASP.NET Identity Framework.
- Download and investigate source codes.