{"id":844,"date":"2013-12-20T13:58:00","date_gmt":"2013-12-20T13:58:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/12\/20\/announcing-preview-of-microsoft-aspnet-identity-2-0-0-alpha1\/"},"modified":"2013-12-20T13:58:00","modified_gmt":"2013-12-20T13:58:00","slug":"announcing-preview-of-microsoft-aspnet-identity-2-0-0-alpha1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-preview-of-microsoft-aspnet-identity-2-0-0-alpha1\/","title":{"rendered":"Announcing preview of Microsoft.AspNet.Identity 2.0.0-alpha1"},"content":{"rendered":"<p><span style=\"font-size: small\">Today, we are releasing a preview of ASP.NET Identity. The main focus in this release was to fix issues with the 1.0 release and build upon the 1.0 Framework to add more features such as Account Confirmation, Password Reset etc. Please read the known issues section below before trying out this preview.<\/span>&nbsp;<\/p>\n<h2><strong>Download this release<\/strong><\/h2>\n<p><span style=\"font-size: small\">You can download ASP.NET Identity as preview NuGet packages from the NuGet gallery. You can install or update to these pre-release packages through NuGet using the NuGet Package Manager Console, like this: <\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\">Install-Package Microsoft.AspNet.Identity.EntityFramework &ndash;Version 2.0.0-alpha1 &ndash;Pre <\/span><\/li>\n<li><span style=\"font-size: small\">Install-Package Microsoft.AspNet.Identity.Core -Version 2.0.0-alpha1 &ndash;Pre <\/span><\/li>\n<li><span style=\"font-size: small\">Install-Package Microsoft.AspNet.Identity.OWIN -Version 2.0.0-alpha1 &ndash;Pre<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small\">Please remember to select the &ldquo;Include Prerelease&rdquo; option when searching for packages using the NuGet Package Manager or the Package Manager Console. For more information on how to install pre-release packages please read <\/span><a href=\"http:\/\/docs.nuget.org\/docs\/Reference\/Versioning#Prerelease_Versions\"><span style=\"font-size: small\">http:\/\/docs.nuget.org\/docs\/Reference\/Versioning#Prerelease_Versions<\/span><\/a><span style=\"font-size: small\"> and <\/span><a href=\"http:\/\/docs.nuget.org\/docs\/release-notes\/nuget-1.7#Show_prerelease_packages_in_the_Manage_NuGet_packages_dialog\"><span style=\"font-size: small\">http:\/\/docs.nuget.org\/docs\/release-notes\/nuget-1.7#Show_prerelease_packages_in_the_Manage_NuGet_packages_dialog<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>What&rsquo;s in this release<\/strong><\/h2>\n<p><span style=\"font-size: small\">Following is the list of features and major issues that were fixed.<\/span><\/p>\n<h3><strong>Account Confirmation<\/strong><\/h3>\n<p><span style=\"font-size: small\">The ASP.NET Identity system now supports Account Confirmation. This is a fairly common scenario in most websites today where when you register for a new account on the website, you are required to confirm your email before you could do anything in the website. Email Confirmation is useful because it prevents bogus accounts from being created. This is extremely useful if you are using email as a method of communicating with the users of your website such as Forum sites, banking, ecommerce, social web sites.<\/span><\/p>\n<p><span style=\"font-size: small\"><strong>Note<\/strong>: To send emails you can configure SMTP Server or use some of the popular email services such as SendGrid (<\/span><a href=\"http:\/\/sendgrid.com\/windowsazure.html\"><span style=\"font-size: small\">http:\/\/sendgrid.com\/windowsazure.html<\/span><\/a><span style=\"font-size: small\">) which integrate nicely with Windows Azure and require no configuration on the application developer<\/span><\/p>\n<p><span style=\"font-size: small\">In the sample project below, you need to hook up the Email service for sending emails. You will not be able to reset your password until you confirm your account<\/span><span style=\"font-size: small\">&nbsp;<\/span><\/p>\n<h3><strong>Password Reset<\/strong><\/h3>\n<p><span style=\"font-size: small\">Password Reset is a feature where the user can reset their passwords if they have forgotten their password. <\/span><span style=\"font-size: small\">&nbsp;<\/span><\/p>\n<h3><strong>Security Token Provider<\/strong><\/h3>\n<p><span style=\"font-size: small\">Support a way to regenerate the Security Token for the user in cases when the User changes there password or any other security related information such as removing an associated login(such as Facebook, Google, Microsoft Account etc). This is needed to ensure that any tokens generated with the old password are invalidated. In the sample project, if you change the users password then a new token is generated for the user and any previous tokens are invalidated. <\/span><span style=\"font-size: small\">This feature provides an extra layer of security to your application since when you change your password, you will be logged out from everywhere (all other browsers) where you have logged into this application.<\/span><\/p>\n<p><span style=\"font-size: small\">You can configure this in Startup.Auth.cs as follows. You can specify how often should the OWIN cookie middleware check if the Security Token for the current user is valid. This is in the sample project listed below.<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7e237ba5-b7e4-48be-bbca-e33ba9e126f4\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #008000\">\/\/ Enable the application to use a cookie to store information for the signed in user<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #008000\">\/\/ and to use a cookie to temporarily store information about a user logging in with a third party login provider<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #008000\">\/\/ Configure the sign in cookie<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">app.UseCookieAuthentication(<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">CookieAuthenticationOptions<\/span><span style=\"background: #ffffff;color: #000000\"> {<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationType = <\/span><span style=\"background: #ffffff;color: #2b91af\">DefaultAuthenticationTypes<\/span><span style=\"background: #ffffff;color: #000000\">.ApplicationCookie,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">LoginPath = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">PathString<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;\/Account\/Login&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">),<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Provider = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">CookieAuthenticationProvider<\/span><span style=\"background: #ffffff;color: #000000\"> {<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">OnValidateIdentity = <\/span><span style=\"background: #ffffff;color: #2b91af\">SecurityStampValidator<\/span><span style=\"background: #ffffff;color: #000000\">.OnValidateIdentity&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUserManager<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUser<\/span><span style=\"background: #ffffff;color: #000000\">&gt;(<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">validateInterval: <\/span><span style=\"background: #ffffff;color: #2b91af\">TimeSpan<\/span><span style=\"background: #ffffff;color: #000000\">.FromSeconds(5),<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">regenerateIdentity: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager))<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">});<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<h3><strong>Make the type of Primary Key be extensible for Users and Roles<\/strong><\/h3>\n<p><span style=\"font-size: small\">In 1.0 the type of PK for Users and Roles was strings. This means when the ASP.NET Identity system was persisted in Sql Server using Entity Framework, we were using nvarchar. There were lots of discussions around this default implementation on Stack Overflow and based on the incoming feedback, we have provided an extensibility hook where you can specify what should be the PK of your Users and Roles table. This extensibility hook is particularly useful if you are migrating your application and the application was storing UserIds are GUIDs or ints.<\/span><\/p>\n<p><span style=\"font-size: small\">Since you are changing the type of PK for Users and Roles, you need to plug in the corresponding classes for Claims, Logins which take in the correct PK. Following is a snippet of code which shows how you can change the PK to be int<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:88479b9d-db87-4d03-9728-f73f363b6ff4\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUser<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityUser&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserLogin<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserRole<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserClaim<\/span><span style=\"background: #ffffff;color: #000000\">&gt;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">CustomRole<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityRole&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserRole<\/span><span style=\"background: #ffffff;color: #000000\">&gt;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> CustomRole() { }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> CustomRole(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> name) { Name = name; }<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserRole<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityUserRole&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">&gt; { }<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserClaim<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityUserClaim&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">&gt; { }<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserLogin<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityUserLogin&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">&gt; { }<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationDbContext<\/span><span style=\"background: #ffffff;color: #000000\"> : IdentityDbContext&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUser<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomRole<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserLogin<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserRole<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #2b91af\">CustomUserClaim<\/span><span style=\"background: #ffffff;color: #000000\">&gt;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\">&nbsp;<\/span><\/p>\n<h3><strong>Support IQueryable on Users and Roles<\/strong><\/h3>\n<p><span style=\"font-size: small\">We have added support for IQueryable on UsersStore and RolesStore so you can easily get the list of Users and Roles. <\/span><\/p>\n<p><span style=\"font-size: small\">For eg. the following code uses the IQueryable&nbsp; and shows how you can get the list of Users from UserManager. You can do the same for getting list of Roles from RoleManager<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d011540a-e946-4b65-8298-b8f73d7a3068\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #008000\">\/\/<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #008000\">\/\/ GET: \/Users\/<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #2b91af\">Task<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\">&gt; Index()<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> View(<\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> UserManager.Users.ToListAsync());<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<h4>&nbsp;<\/h4>\n<h3><strong>Support Delete operation through the UserManager<\/strong><\/h3>\n<p><span style=\"font-size: small\">In 1.0, if you had to delete a User, you could not do it through the UserManager. We have fixed this issue in this release so you can do the following to delete a user<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:39808b1a-edd0-4349-890e-668e102099dc\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> user = <\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> UserManager.FindByIdAsync(id);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">if<\/span><span style=\"background: #ffffff;color: #000000\"> (user == <\/span><span style=\"background: #ffffff;color: #0000ff\">null<\/span><span style=\"background: #ffffff;color: #000000\">)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> HttpNotFound();<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> result = <\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> UserManager.DeleteAsync(user);<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<h3>&nbsp;<\/h3>\n<h3><strong>UserManagerFactory Middleware<\/strong><\/h3>\n<p><span style=\"font-size: small\">You can use Factory implementation to get an instance of UserManager from the OWIN context. This pattern is similar to what we use for getting AuthenticationManager from OWIN context for SignIn and SignOut. This is a recommended way of getting an instance of UserManager per request for the application.<\/span><\/p>\n<p><span style=\"font-size: small\">Following snippet of code shows how you can configure this middleware in StartupAuth.cs. This is in the sample project listed below.<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c6fddbb-cfc1-46ef-aac3-ab7ba7a2e0e0\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #008000\">\/\/ Configure the UserManager<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">app.UseUserManagerFactory(<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">UserManagerOptions<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUserManager<\/span><span style=\"background: #ffffff;color: #000000\">&gt;()<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">DataProtectionProvider = app.GetDataProtectionProvider(),<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Provider = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">UserManagerProvider<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUserManager<\/span><span style=\"background: #ffffff;color: #000000\">&gt;()<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">OnCreate = <\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUserManager<\/span><span style=\"background: #ffffff;color: #000000\">.Create<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">});<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\">Following snippet of code shows how you can get an instance of UserManager<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:04ab0629-9408-4049-a413-01c9f9cc107f\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #000000\">HttpContext.GetOwinContext().GetUserManager&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationUserManager<\/span><span style=\"background: #ffffff;color: #000000\">&gt;();<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<h3>&nbsp;<\/h3>\n<h3><strong>DbContextFactory Middleware<\/strong><\/h3>\n<p><span style=\"font-size: small\">ASP.NET Identity uses EntityFramework for persisting the Identity system in Sql Server. To do this the Identity System has a reference to the ApplicationDbContext. The DbContextFactory Middleware returns you an instance of the ApplicationDbContext per request which you can use in your application.<\/span><\/p>\n<p><span style=\"font-size: small\">Following code shows how you can configure it in StartupAuth.cs. The code for this middleware is in the sample project.<\/span><\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6570cf49-4439-4afc-bf62-5000d7fcf86c\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #000000\">app.UseDbContextFactory(<\/span><span style=\"background: #ffffff;color: #2b91af\">ApplicationDbContext<\/span><span style=\"background: #ffffff;color: #000000\">.Create);<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<h2><strong>Samples<\/strong><\/h2>\n<ul>\n<li><span style=\"font-size: small\">We have a sample project which shows these new features at <\/span><span style=\"font-size: small\"><a title=\"https:\/\/aspnet.codeplex.com\" href=\"https:\/\/aspnet.codeplex.com\">https:\/\/aspnet.codeplex.com<\/a>. Please look for the Identity folder in the source.&nbsp;https:\/\/aspnet.codeplex.com\/SourceControl\/latest#Samples\/Identity<\/span><\/li>\n<ul>\n<li><span style=\"font-size: small\">This project shows how a ASP.NET Web Application project template would look like. Please look at the readme in the project for instructions on how to run.<\/span><\/li>\n<\/ul>\n<li><span style=\"font-size: small\">For documentation on ASP.NET Identity 1.0 please visit <\/span><a href=\"http:\/\/www.asp.net\/identity\"><span style=\"font-size: small\">http:\/\/www.asp.net\/identity<\/span><\/a><span style=\"font-size: small\">. We are working on adding more documentation on this site.<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><strong>Known Issues\/ Breaking change<\/strong><\/h2>\n<p><span style=\"font-size: small\">As part of these new features such as Account Confirmation and Password Reset, we have added two new properties to the IdentityUser class namely &lsquo;Email&rsquo; and &lsquo;IsConfirmed&rsquo;. This results in a change of the schema created by the ASP.NET Identity system in 2.0. Updating the packages to 2.0 in an existing application (which was using 1.0) will cause the application to fail since the underlying Entity Framework model has been changed. You need to update your database schema to use the 2.0 features. This can be done using Entity Framework migrations. For more details on how to update your application from 1.0 to 2.0, please visit this detailed blog post<\/span> <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/12\/20\/updating-asp-net-applications-from-asp-net-identity-1-0-to-2-0-0-alpha1.aspx\">http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/12\/20\/updating-asp-net-applications-from-asp-net-identity-1-0-to-2-0-0-alpha1.aspx<\/a><\/p>\n<p><span style=\"font-size: small\"><strong>Note:<\/strong> <\/span><\/p>\n<p><span style=\"font-size: small\">This is an area of migration which we are trying to see if we can provide a better story before we release the final version. Since the new features requires database schema updates, there is a user action involved to update the database manually. It is due to this reason that we have updated the package version to 2.0.0 as per SemVer guidelines, since on installing this version will break existing applications and you have to update the database schema.<\/span><\/p>\n<p><span style=\"font-size: small\">ASP.NET Identity 2.0.0-alpha1 depends upon EntityFramework 6.1.0-alpha1 which was also released today (<a href=\"http:\/\/blogs.msdn.com\/b\/adonet\/archive\/2013\/12\/20\/ef-6-1-alpha-1-available.aspx\">http:\/\/blogs.msdn.com\/b\/adonet\/archive\/2013\/12\/20\/ef-6-1-alpha-1-available.aspx<\/a>) since in EntityFramework 6.1.0-alpha1, there were bug fixes which helped in improving the migration scenario from Identity 1.0 &ndash; 2.0<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Give feedback and get support<\/strong><\/h2>\n<ul>\n<li><span style=\"font-size: small\">If you find any bugs please open them at our Codeplex Site where we track all our bugs <\/span><a href=\"https:\/\/aspnetidentity.codeplex.com\/\"><span style=\"font-size: small\">https:\/\/aspnetidentity.codeplex.com\/<\/span><\/a><\/li>\n<li><span style=\"font-size: small\">If you want to discuss these features, please discuss them on Stack Overflow and use the following tag &ldquo;asp.net-identity&rdquo;<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><strong>What&rsquo;s next<\/strong><\/h2>\n<p><span style=\"font-size: small\">We still have many bugs to fix and a few features to add before we release the final RTM version so do expect a few more previews in the coming months. You can check our roadmap at <\/span><span style=\"font-size: small\"><a href=\"https:\/\/aspnetidentity.codeplex.com\/wikipage?title=Roadmap&amp;version=1\">https:\/\/aspnetidentity.codeplex.com\/wikipage?title=Roadma<\/a>p<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: small\">Thank You for trying out the preview and your feedback for ASP.NET<\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we are releasing a preview of ASP.NET Identity. The main focus in this release was to fix issues with the 1.0 release and build upon the 1.0 Framework to add more features such as Account Confirmation, Password Reset etc. Please read the known issues section below before trying out this preview.&nbsp; Download this release [&hellip;]<\/p>\n","protected":false},"author":408,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[],"class_list":["post-844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet"],"acf":[],"blog_post_summary":"<p>Today, we are releasing a preview of ASP.NET Identity. The main focus in this release was to fix issues with the 1.0 release and build upon the 1.0 Framework to add more features such as Account Confirmation, Password Reset etc. Please read the known issues section below before trying out this preview.&nbsp; Download this release [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/408"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=844"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}