{"id":174097,"date":"2013-03-25T03:23:03","date_gmt":"2013-03-24T23:23:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=174097"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=174097","title":{"rendered":"<span class=\"post_title\">\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Asp.Net MVC<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440! \u0425\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 ASP.NET MVC. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0410 \u0442\u0430\u043a \u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430 \u0440\u043e\u043b\u044f\u0445. <br \/>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c ASP.NET MVC \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438 \u00ab\u0431\u044b\u0432\u0430\u043b\u044b\u0435\u00bb (\u043e\u043f\u044b\u0442\u043d\u044b\u0435) \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043f\u043e\u0434\u0447\u0435\u0440\u043f\u043d\u0443\u0442 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0434\u0435\u0438. \u041a\u0440\u0438\u0442\u0438\u043a\u0430, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f. \u0412\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0435\u0439 \u0446\u0435\u043b\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0439 (\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439) \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u043e\u043b\u0435\u0439. \u041e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u043d\u0430\u043c\u0435\u043a \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0440\u043e\u043b\u0435\u0439. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043d\u0430 membership \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u0445, \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c, \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041e\u043d\u0430 \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0435\u0435 \u043c\u0438\u043d\u0443\u0441 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438.<\/h3>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u0412 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 ASP.NET MVC \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0438\u0434\u043e\u0432 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<ul>\n<li>Windows Authentication (\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f Windows) \u2013 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e AD. \u0412\u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e AD, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e IIS, \u0447\u0435\u0440\u0435\u0437 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440. \u0414\u0430\u043d\u043d\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439; <\/li>\n<li>Password Authentication (\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Password) \u2013 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441\u043b\u0443\u0436\u0431\u0430 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u0430\u044f Microsoft;<\/li>\n<li>Form Authentication (\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u043e\u0440\u043c) \u2013 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0438\u0434 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442.\u041e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u044e, \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e html \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u0430 \u0444\u043e\u0440\u043c\u0435 \u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0438 \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0433\u0434\u0435 \u043e\u043d\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u043e\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0432\u0438\u0434 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c. <\/li>\n<\/ul>\n<p>  \u0412 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u043e\u0440\u043c\u0443 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 cookie-\u043d\u0430\u0431\u043e\u0440. Cookie \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430, \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u043e\u0440\u043c\u0443, \u0441\u043b\u0443\u0436\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 Encript \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 System.Web.Security.FormAuthentication. \u0414\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 Decrypt. \u0427\u0435\u043c \u0445\u043e\u0440\u043e\u0448 \u043a\u043b\u0430\u0441\u0441 FormAuthentication? \u0422\u0435\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0438\u0444\u0440\u0443\u044e\u0442 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0411\u0435\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 cookie \u0444\u0430\u0439\u043b\u0430 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0430 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e Http \u0437\u0430\u043f\u0440\u043e\u0441\u0430 HttpContext.User.Identity.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">[Serializable] \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438. public abstract class AbstractIdentity&lt;TAccount, TRole&gt;: MarshalByRefObject, IIdentity {         protected AbstractIdentity()         {             Id = long.MinValue;         }          private bool _isInitialized = false;          public long Id { get; set; }         public string Name { get; set; }         public string AuthenticationType          {             get              {                   return String.Format(&quot;CustomizeAuthentication_{0}&quot;, typeof(TAccount).Name);             }         }         public string[] Role { get; set; }         public TRole[] Roles { get; set; }         public bool IsAuthenticated         {             get { return Id != long.MinValue; }         }         public bool CheckRole(TRole role)         {             return Role.All(r =&gt; r.Equals(role.ToString()));         }          public void SetAccount(TAccount account)         {             Id = GetId(account);             Name = GetName(account);                          Roles = GetRole(account);             Role = Roles.Select(c=&gt;c.ToString()).ToArray();             InitializeMoreFields(account);             _isInitialized = true;         }         protected virtual void InitializeMoreFields(TAccount account) { }          protected abstract long GetId(TAccount account);         protected abstract string GetName(TAccount account);         protected abstract TRole[] GetRole(TAccount account);          public string Serialize()         {             if (!_isInitialized)                 throw new AccountNotSetException();              using (var stream = new MemoryStream())             {                 var formatter = new XmlSerializer(GetType());                 formatter.Serialize(stream, this);                 return Encoding.UTF8.GetString(stream.ToArray());             }         }         public static TIdenty Deserialize&lt;TIdenty&gt;(string value)             where TIdenty : AbstractIdentity&lt;TAccount, TRole&gt;         {             using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(value)))             {                 var formatter = new XmlSerializer(typeof(TIdenty));                 return (TIdenty)formatter.Deserialize(stream);             }         } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 HTTP \u043c\u043e\u0434\u0443\u043b\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0412 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u044f AuthenticateRequest, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u0434\u043b\u0438\u043d\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043a\u0430\u0434\u0438\u0440\u0443\u0435\u043c cookie, \u0441\u043e\u0437\u0434\u0430\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0442\u0435\u043a\u0449\u0438\u0439 HTTP \u0437\u0430\u043f\u0440\u043e\u0441.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">\/\/TIdenty - \u0422\u0438\u043f \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438. public abstract class AbstractAutentificationModule&lt;TIdenty, TAccount, TRole&gt; : IHttpModule         where TIdenty : AbstractIdentity&lt;TAccount, TRole&gt; {         public void Init(HttpApplication context)         {             context.AuthenticateRequest += OnAuthenticateRequest;         }          private static void OnAuthenticateRequest(object sender, EventArgs e)         {             var application = (HttpApplication)sender;              var context = application.Context;              if (context.User != null && context.User.Identity.IsAuthenticated)                 return;              var cookieName = FormsAuthentication.FormsCookieName;              var cookie = application.Request.Cookies[cookieName.ToUpper()];              if (cookie == null)                 return;             try             {                 var ticket = FormsAuthentication.Decrypt(cookie.Value);                 var identity = AbstractIdentity&lt;TAccount, TRole&gt;.Deserialize&lt;TIdenty&gt;(ticket.UserData);                 var principal = new GenericPrincipal(identity, identity.Role);                 context.User = principal;                 Thread.CurrentPrincipal = principal;             }             catch             {}         }          public void Dispose()         {} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 cookie. \u0414\u0430\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 HTTP \u0437\u0430\u043f\u0440\u043e\u0441.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">\/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. public interface IAuthorizeService&lt;in TAccount&gt; {         void SignIn(TAccount account, bool createPersistentCookie);         void SignOut(); }  \/\/TIdenty - \u0422\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438. public abstract class AbstractAuthorizeService&lt;TIdentity, TAccount, TRole&gt; : IAuthorizeService&lt;TAccount&gt;        where TIdentity : AbstractIdentity&lt;TAccount, TRole&gt;, new() {         private const int TICKET_VERSION = 1;         private const int EXPIRATION_MINUTE = 60;          public void SignIn(TAccount account, bool createPersistentCookie)         {             var accountIdentity = CreateIdentity(account);              var authTicket = new FormsAuthenticationTicket(TICKET_VERSION,                                                             accountIdentity.Name,                                                             DateTime.Now,                                                             DateTime.Now.AddMinutes(EXPIRATION_MINUTE),                                                             createPersistentCookie,                                                             accountIdentity.Serialize());              CreateCookie(authTicket);              HttpContext.Current.User = new GenericPrincipal(accountIdentity, accountIdentity.Role);         }          private TIdentity CreateIdentity(TAccount account)         {             var accountIdentity = new TIdentity();             accountIdentity.SetAccount(account);             return accountIdentity;         }          private void CreateCookie(FormsAuthenticationTicket ticket)         {                var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,  FormsAuthentication.Encrypt(ticket))             {                 Expires = DateTime.Now.Add(FormsAuthentication.Timeout),             };              HttpContext.Current.Response.Cookies.Add(authCookie);         }          public void SignOut()         {             FormsAuthentication.SignOut();         } }  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043c\u0435\u0442\u043e\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 Generic, \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443(RuleFactory). <br \/>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IRule \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public interface IRule {                bool Check(IIdentity user); }  \/\/\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \/\/TIdenty - \u0422\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438. internal class Rule&lt;TIdentity, TAccount, TRole&gt; : IRule  \t\twhere TIdentity : AbstractIdentity&lt;TAccount, TRole&gt; {                 private readonly Func&lt;TIdentity, bool&gt; _check;  \t\tpublic Rule(Func&lt;TIdentity, bool&gt; check) \t\t{ \t\t\tif (check == null)  \t\t\t\tthrow new ArgumentNullException(&quot;check&quot;);  \t\t\t_check = check; \t\t}  \t\tpublic bool Check (IIdentity user) \t\t{ \t\t\treturn _check((TIdentity) user); \t\t} }  \/\/\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043f\u0440\u0430\u0432\u0438\u043b \/\/TIdenty - \u0422\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438. public class RuleFactory&lt;TIdentity, TAccount, TRole&gt; \t\twhere TIdentity : AbstractIdentity&lt;TAccount, TRole&gt; { \t\tpublic IRule Create(Func&lt;TIdentity, bool&gt; rule)  \t\t{ \t\t\treturn new Rule&lt;TIdentity, TAccount, TRole&gt; (rule); \t\t} }  \/\/\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 public abstract class AbstractAutintificateAttribute : AuthorizeAttribute { \tprivate readonly ICollection&lt;IRule&gt; _rules = new List&lt;IRule&gt; ();          private readonly bool _isNotSimpleAuthentication;          protected AbstractAutintificateAttribute(bool isNotSimpleAuthentication)         {             _isNotSimpleAuthentication = isNotSimpleAuthentication;         }          protected void AddRule(IRule rule)  \t\t{ \t\t\tif (rule == null) \t\t\t\tthrow new ArgumentNullException (&quot;rule&quot;);  \t\t\t_rules.Add (rule); \t\t}          protected override bool AuthorizeCore(HttpContextBase httpContext)         {             if (httpContext == null)                 throw new ArgumentNullException(&quot;httpContext&quot;);              if (httpContext.User == null || !httpContext.User.Identity.IsAuthenticated)                 return false;              var isAuthorize = false;             isAuthorize |= _rules.Any(rule =&gt; rule.Check(httpContext.User.Identity));             isAuthorize |= httpContext.Request.IsAuthenticated && !_isNotSimpleAuthentication; \t\t\treturn isAuthorize;         }           protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)         {             var context = filterContext.HttpContext;              var appPath = context.Request.ApplicationPath == &quot;\/&quot;                                 ? string.Empty                                 : context.Request.ApplicationPath;              var loginUrl = FormsAuthentication.LoginUrl;             var path = HttpUtility.UrlEncode(context.Request.Url.PathAndQuery);              var url = String.Format(&quot;{0}{1}?ReturnUrl={2}&quot;, appPath, loginUrl, path);              if (!filterContext.IsChildAction)                 filterContext.Result = new RedirectResult(url);         } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043e\u0441\u0443\u043f \u043a \u0442\u0435\u043a\u0443\u0448\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">\/\/TIdenty - \u0422\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \/\/TAccount -   \u0422\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435. \/\/TRole - \u0422\u0438\u043f \u0440\u043e\u043b\u0438.   public abstract class AbstractController&lt;TIdenty, TAccount, TRole&gt; : Controller         where TIdenty : AbstractIdentity&lt;TAccount, TRole&gt; {         protected AbstractController()         {             _user = new Lazy&lt;TIdenty&gt;(() =&gt; HttpContext.User.Identity as TIdenty);         }          private readonly Lazy&lt;TIdenty&gt; _user;           protected TIdenty CurrentUser { get { return _user.Value; } } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u0412\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u044b\u0445 generic \u0442\u0438\u043f\u043e\u0432.<br \/>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0441 \u0447\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class ExampleIdentity : AbstractIdentity&lt;Account, Role&gt; {         public string Email { get; set; }          \/\/\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0432\u043e\u0437\u0432\u0440\u043e\u0449\u0430\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         protected override long GetId(Account account)         {             return account.Id;         }         \/\/\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0432\u043e\u0437\u0432\u0440\u043e\u0449\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f(\u043b\u043e\u0433\u0438\u043d)         protected override string GetName(Account account)         {             return account.Login;         }          \/\/\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0432\u043e\u0437\u0432\u0440\u043e\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u043e\u043b\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         protected override Role[] GetRole(Account account)         {             return new []{ account.Role };         }           \/\/\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a\u0438\u0435 \u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0432\u0430. \u0438\u0445 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0434\u0435\u0441\u044c         protected override void InitializeMoreFields(Account account)         {             Email = account.Email;         } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0430\u0443\u0442\u0435\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class ExampleAutintificateModule : AbstractAutentificationModule&lt;ExampleIdentity, Account, Role&gt; { } <\/code><\/pre>\n<p>  \u041d\u0435\u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u0448\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Web.config, \u0438 \u0442\u0430\u043c \u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0438\u043f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;configuration&gt;    ....   &lt;system.web&gt;      ....      &lt;httpModules&gt;          &lt;remove name=&quot;FormsAuthentication&quot; \/&gt;          &lt;add name=&quot;FormsAuthentication&quot; type=&quot;Example.Infrostructure.ExampleAutintificateModule&quot; \/&gt;     &lt;\/httpModules&gt;     &lt;authentication mode=&quot;Forms&quot;&gt;         &lt;!--loginUrl \u043f\u0443\u0442\u044c \u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 --&gt;          &lt;forms loginUrl=&quot;~\/User\/Login&quot; timeout=&quot;2880&quot; \/&gt;     &lt;\/authentication&gt;   &lt;\/system.web&gt;   &lt;\/configuration&gt;  &lt;system.webServer&gt;    ....    &lt;modules runAllManagedModulesForAllRequests=&quot;true&quot;&gt;       &lt;remove name=&quot;FormsAuthentication&quot; \/&gt;       &lt;add name=&quot;FormsAuthentication&quot; type=&quot;Example.Infrostructure.ExampleAutintificateModule&quot; \/&gt;     &lt;\/modules&gt;  &lt;\/system.webServer&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class ExampleAuthorizeService : AbstractAuthorizeService&lt;ExampleIdentity, Account, Role&gt; {   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public abstract class ExampleController : AbstractController&lt;ExampleIdentity, Account, Role&gt; { } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">\/\/\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043f\u0440\u0430\u0432\u0438\u043b public class ExampleRuleFactory : RuleFactory&lt;ExampleIdentity, Account, Role&gt; {  }  \/\/\u0412\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0448\u044c\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0438. public class ExampleAuthintificationAtribute : AbstractAutintificateAttribute {         private readonly ExampleRuleFactory _ruleFactory = new ExampleRuleFactory();           public ExampleAuthintificationAtribute(params Role[] allowedRole) : base(allowedRole.Any())         {             \/\/\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0445\u0438 \u0440\u043e\u043b\u0438 \u0435\u0441\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435             AddRule(_ruleFactory.Create(account =&gt; allowedRole.Intersect(account.Roles).Any()));              \/\/\u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0434\u043c\u0438\u043d, \u0442\u043e \u043e\u043d \u0432\u0438\u0434\u0438\u0442 \u0432\u0441\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0438             AddRule(_ruleFactory.Create(account =&gt; account.Roles.Any(c=&gt;c == Role.Admin)));         } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b nugget-package \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0443, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u043c\u0430\u043d\u0434\u043e\u0439:   <\/p>\n<pre><code class=\"cs\">Install-Package MvcCustomizableFormAuthentication <\/code><\/pre>\n<p>  \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/github.com\/nomit007\/MvcCustomizableFormAuthentication\">github<\/a>, \u0442\u0430\u043c \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <br \/>  \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0443\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0416\u0434\u0443 \u0441\u043e\u0432\u0435\u0442\u043e\u0432, \u043a\u0440\u0438\u0442\u0438\u043a\u0438, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<br \/>  <b>P.S.<\/b> \u041d\u0435\u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043e unit-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \t\t\t \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\/174097\/\"> http:\/\/habrahabr.ru\/post\/174097\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440! \u0425\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 ASP.NET MVC. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0410 \u0442\u0430\u043a \u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430 \u0440\u043e\u043b\u044f\u0445. <br \/>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c ASP.NET MVC \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438 \u00ab\u0431\u044b\u0432\u0430\u043b\u044b\u0435\u00bb (\u043e\u043f\u044b\u0442\u043d\u044b\u0435) \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043f\u043e\u0434\u0447\u0435\u0440\u043f\u043d\u0443\u0442 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0434\u0435\u0438. \u041a\u0440\u0438\u0442\u0438\u043a\u0430, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f. \u0412\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/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-174097","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/174097","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=174097"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/174097\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}