{"id":227351,"date":"2014-06-24T11:56:02","date_gmt":"2014-06-24T07:56:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=227351"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=227351","title":{"rendered":"<span class=\"post_title\">\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ASP.NET Identity<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0445\u043e\u0434 ASP.NET MVC 5 \u043e\u0437\u043d\u0430\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c ASP.NET Identity. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043d\u0430\u0437\u044b\u0432\u0430\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0435\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 (ASP.NET MVC, Web Forms, Web Pages, Web API \u0438 SignalR), \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e, \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430 OWIN, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c NuGet \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0432\u0448\u0438\u0441\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043a ASP.NET Identity, \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u0437\u0430\u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f \u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u0432\u0435\u0431-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 ASP.NET. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ASP.NET Identity.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u043e\u0431\u0440\u043e\u0434\u0438\u0432 \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443 \u0432 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043f\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 MVC 5, \u044f \u043d\u0430\u0448\u0435\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Entity Framework \u043a\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0430\u0436\u0435 <a href=\"http:\/\/www.asp.net\/identity\/overview\/getting-started\">\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441<\/a>, \u043a \u043c\u043e\u0435\u043c\u0443 \u0432\u0435\u043b\u0438\u043a\u043e\u043c\u0443 \u0440\u0430\u0441\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443, \u043d\u0435 \u0441\u043c\u043e\u0433 \u0432 \u0434\u043e\u043b\u0436\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u0442\u0435\u043c\u0443 \u0438 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f MVC-\u043f\u0440\u043e\u0435\u043a\u0442, \u0433\u0434\u0435 \u043c\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 Owin, Katana \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 ASP.NET Identity. \u0415\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0442\u0435\u0440\u043c\u0438\u043d Owin \u0432\u0432\u043e\u0434\u0438\u0442 \u0432\u0430\u0441 \u0432 \u0437\u0430\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c <a href=\"http:\/\/habrahabr.ru\/post\/202018\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>. <\/p>\n<p>  <b>1. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f: Microsoft.AspNet.Identity.Core, Microsoft.Owin, Microsoft.Owin.Security + \u0432\u0441\u0435, \u043e\u0442 \u043d\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0438 \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435. \u041b\u0435\u0433\u043a\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"http:\/\/www.nuget.org\/\">NuGet Package Manager<\/a>. \u0427\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c NuGet \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">Install-Package Microsoft.AspNet.Identity.Core <\/code><\/pre>\n<p>  <b>2. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:<\/b>  <\/p>\n<pre><code class=\"cs\">public class ApplicationUser : IUser {         public ApplicationUser(string name)         {                         Id = Guid.NewGuid().ToString();             UserName = name;         }          public string Id { get; private set; }         public string UserName { get; set; } }<\/code><\/pre>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Microsoft.AspNet.Identity.<b>IUser<\/b> \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439 Id \u0438 UserName. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0432\u0430\u043c \u043f\u043e\u043b\u044f (Email, Password, City \u0438 \u0442.\u0434.)<\/p>\n<pre><code class=\"cs\">public class CustomUserStore : IUserStore&lt;ApplicationUser&gt; {         static readonly List&lt;ApplicationUser&gt; Users = new List&lt;ApplicationUser&gt;();          public void Dispose()         {             throw new NotImplementedException();         }          public Task CreateAsync(ApplicationUser user)         {             return Task.Factory.StartNew(() =&gt; Users.Add(user));         }          public Task UpdateAsync(ApplicationUser user)         {             throw new NotImplementedException();         }          public Task DeleteAsync(ApplicationUser user)         {             throw new NotImplementedException();         }          public Task&lt;ApplicationUser&gt; FindByIdAsync(string userId)         {             throw new NotImplementedException();         }          public Task&lt;ApplicationUser&gt; FindByNameAsync(string userName)         {             return Task&lt;ApplicationUser&gt;.Factory.StartNew(() =&gt; Users.FirstOrDefault(u =&gt; u.UserName == userName));         } }<\/code><\/pre>\n<p>  <b>CustomUserStore<\/b>, \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (Create, Update, Delete) \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438. \u0417\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 Users. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0435, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0434\u043b\u044f \u0432\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 Task \u0438 Task. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u041f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/142372\/\">\u0432\u043e\u0442<\/a>).<\/p>\n<pre><code class=\"cs\">public class CustomUserManager : UserManager&lt;ApplicationUser&gt; {         public CustomUserManager(CustomUserStore store)             : base(store)         {                 this.PasswordHasher = new CustomPasswordHasher();         }          public override Task&lt;ApplicationUser&gt; FindAsync(string userName, string password)         {             Task&lt;ApplicationUser&gt; taskInvoke = Task&lt;ApplicationUser&gt;.Factory.StartNew(() =&gt;             {                                PasswordVerificationResult result = this.PasswordHasher.VerifyHashedPassword(userName, password);                 if (result == PasswordVerificationResult.SuccessRehashNeeded)                 {                         return Store.FindByNameAsync(userName).Result;                 }                 return null;             });             return taskInvoke;         } }  public class CustomPasswordHasher : PasswordHasher {         public override string HashPassword(string password)         {             return base.HashPassword(password);         }          public override PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword)         {                        if (true)             {                 return PasswordVerificationResult.SuccessRehashNeeded;             }             else             {                 return PasswordVerificationResult.Failed;             }         } } <\/code><\/pre>\n<p>  <b>CustomUserManager<\/b> \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438(\u0437\u0430\u043c\u0435\u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c\u0443 Membership Provider). \u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u043c Microsoft.AspNet.Identity.<b>UserManager<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 FindAsync(), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u043e\u043b\u044c, \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0445\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u044e\u0437\u0435\u0440. \u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 UserManeger \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 PasswordHasher \u2014 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438. \u0422\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 VerifyHashedPassword \u0438\u043c\u0435\u0435\u0442 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u0438\u0434. \u0412\u044b \u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0442\u0430\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0430\u0440\u043e\u043b\u044f.<\/p>\n<p>  <b>3. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0430\u0448\u0438\u043c CustomUserManager. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 Startup.cs, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0431\u043e\u0440\u043a\u043e\u0439 Owin \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443:<\/b><\/p>\n<pre><code class=\"cs\">        app.CreatePerOwinContext(CustomUserManager.Create); <\/code><\/pre>\n<p>  <b>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c CustomUserManager \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<\/b><\/p>\n<pre><code class=\"cs\">public class TestController : ApiController {         private static CustomUserManager _customUserManager;          public CustomUserManager UserManager         {             get             {                 return _customUserManager ??                        (_customUserManager = HttpContext.Current.GetOwinContext().GetUserManager&lt;CustomUserManager&gt;());             }         }         public async Task&lt;bool&gt; Authenticate(string name, string password)         {            if (await UserManager.FindAsync(name, password) != null)             {                 return true;             }              return false;         } }  <\/code><\/pre>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b UserManager, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 CustomUserStore (\u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u0430\u0448\u0435\u0433\u043e UserManager), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <b>5. \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 MVC [Authorize] \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u0442\u0438\u043f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Startup<\/b>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cs\">public class Startup {         public void Configuration(IAppBuilder app)         {                 app.UseCookieAuthentication(new CookieAuthenticationOptions                 {                         AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,                         LoginPath = new PathString(&quot;\/Account\/Login&quot;)                 });         } } <\/code><\/pre>\n<p>  \u0421\u043f\u0438\u0441\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432:<br \/>   \u2014 <a href=\"http:\/\/code.msdn.microsoft.com\/Simple-Aspnet-Identiy-Core-7475a961\">Simple Asp.net Identity Core Without Entity Framework<\/a><br \/>   \u2014 <a href=\"http:\/\/blog.iteedee.com\/2014\/03\/asp-net-identity-2-0-cookie-token-authentication\/\">ASP.NET Identity 2.0 Cookie &#038; Token Authentication<\/a><\/p>\n<p>  <b>P.S.<\/b> \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0431\u044e\u0442\u043d\u044b\u043c \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u043d\u0443\u0430\u043b \u043f\u043e ASP.NET Identity. \u0420\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u043b\u044e\u0434\u0435\u0439, \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u0441 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 MVC, \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/227351\/\"> http:\/\/habrahabr.ru\/post\/227351\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0445\u043e\u0434 ASP.NET MVC 5 \u043e\u0437\u043d\u0430\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c ASP.NET Identity. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043d\u0430\u0437\u044b\u0432\u0430\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0435\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 (ASP.NET MVC, Web Forms, Web Pages, Web API \u0438 SignalR), \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e, \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430 OWIN, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c NuGet \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0432\u0448\u0438\u0441\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043a ASP.NET Identity, \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u0437\u0430\u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f \u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u0432\u0435\u0431-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 ASP.NET. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ASP.NET Identity.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-227351","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227351"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227351\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}