{"id":176087,"date":"2013-04-09T22:54:05","date_gmt":"2013-04-09T18:54:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=176087"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=176087","title":{"rendered":"<span class=\"post_title\">ASP.NET MVC \u0423\u0440\u043e\u043a B. Json<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430.<\/b> \u041d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c json. \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 json. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 facebook \u0438 vkontakte. Ajax \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 json (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c). API \u0441\u0430\u0439\u0442\u0430.<\/p>\n<h5>Json \u0438 Json.net<\/h5>\n<p>  Json \u2013 \u044d\u0442\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Javascript. <br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Json:  <\/p>\n<pre><code class=\"javascript\">{             &quot;firstName&quot;: &quot;\u0418\u0432\u0430\u043d&quot;,             &quot;lastName&quot;: &quot;\u0418\u0432\u0430\u043d\u043e\u0432&quot;,             &quot;address&quot;: {                 &quot;streetAddress&quot;: &quot;\u041c\u043e\u0441\u043a\u043e\u0432\u0441\u043a\u043e\u0435 \u0448., 101, \u043a\u0432.101&quot;,                 &quot;city&quot;: &quot;\u041b\u0435\u043d\u0438\u043d\u0433\u0440\u0430\u0434&quot;,                 &quot;postalCode&quot;: 101101             },    &quot;phoneNumbers&quot;: [        &quot;812 123-1234&quot;,        &quot;916 123-4567&quot;    \t]   } <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 json \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u043a\u0430\u043a yandex.maps api, facebook api, vk api, bronni api (\u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0442\u0443\u0440\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0440\u0442\u0430\u043b), \u0438 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u0438\u0442\u043a\u043e\u0438\u043d-\u043a\u043e\u0448\u0435\u043b\u044c\u043a\u043e\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f JSON.net \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0442 <a href=\"http:\/\/james.newtonking.com\/pages\/json-net.aspx\">http:\/\/james.newtonking.com\/pages\/json-net.aspx<\/a>. <br \/>  \u0418\u0437\u0443\u0447\u0438\u043c \u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435:  <\/p>\n<ul>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c<\/li>\n<li>\u0418\u0437\u0443\u0447\u0438\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 json \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043d\u0430\u0437\u0430\u0434<\/li>\n<li>\u0414\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/li>\n<li>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 facebook API (\u043f\u0440\u0438\u043c\u0435\u0440) \u2014 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/li>\n<\/ul>\n<p>  \u0423\u0441\u0442\u0440\u0430\u043d\u043e\u0432\u0438\u043c  <\/p>\n<pre><code>PM&gt; Get-Package Json.net  Id                             Version              Description\/Release Notes                         --                             -------              -------------------------                         Newtonsoft.Json                4.5.1                Json.NET is a popular high-performance... PM&gt; Install-Package Newtonsoft.Json Successfully installed 'Newtonsoft.Json 4.5.11'. Successfully added 'Newtonsoft.Json 4.5.11' to LessonProject. <\/code><\/pre>\n<p>\u2003<\/p>\n<p>  \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<br \/>  \u041f\u043e \u044d\u0442\u043e\u0439 <a href=\"http:\/\/james.newtonking.com\/projects\/json\/help\/\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f. \u041c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 json-\u0444\u043e\u0440\u043c\u0430\u0442 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c LessonProject.Console \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0438\u043f User:<\/p>\n<pre><code class=\"cs\">public class User     {         public string Id { get; set; }          public string Name { get; set; }          public string FirstName { get; set; }          public string MiddleName { get; set; }          public string LastName { get; set; }          public string UserName { get; set; }          public string Gender { get; set; }          public string Email { get; set; }     } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0432 json:  <\/p>\n<pre><code class=\"cs\">var user = new User()             {                 Id = &quot;404&quot;,                 Email = &quot;chernikov@gmail.com&quot;,                 UserName = &quot;rollinx&quot;,                 Name = &quot;Andrey&quot;,                 FirstName = &quot;Andrey&quot;,                 MiddleName = &quot;Alexandrovich&quot;,                 LastName = &quot;Chernikov&quot;,                 Gender = &quot;M&quot;             };              var jsonUser = JsonConvert.SerializeObject(user);             System.Console.Write(jsonUser);              System.Console.ReadLine();  <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"javascript\">{&quot;Id&quot;:&quot;404&quot;,&quot;Name&quot;:&quot;Andrey&quot;,&quot;FirstName&quot;:&quot;Andrey&quot;,&quot;MiddleName&quot;:&quot;Alexandrovich&quot;,&quot;LastName&quot;:&quot;Chernikov&quot;,&quot;UserName&quot;:&quot;rollinx&quot;,&quot;Gender&quot;:&quot;M&quot;,&quot;Email&quot;:&quot;chernikov@gmail.com&quot;} <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435:  <\/p>\n<pre><code class=\"cs\">  var jsonUserSource = &quot;{\\&quot;Id\\&quot;:\\&quot;405\\&quot;,\\&quot;Name\\&quot;:\\&quot;Andrey\\&quot;,\\&quot;FirstName\\&quot;:\\&quot;Andrey\\&quot;,\\&quot;MiddleName\\&quot;:\\&quot;Alexandrovich\\&quot;,\\&quot;LastName\\&quot;:\\&quot;Chernikov\\&quot;,\\&quot;UserName\\&quot;:\\&quot;rollinx\\&quot;,\\&quot;Gender\\&quot;:\\&quot;M\\&quot;,\\&quot;Email\\&quot;:\\&quot;chernikov@gmail.com\\&quot;}&quot;;              var user2 = JsonConvert.DeserializeObject&lt;User&gt;(jsonUserSource); <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/390\/8cb\/94b\/3908cb94b4ab738179d90cca35051c63.jpg\"\/><\/p>\n<p>  \u0422.\u0435. \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043e\u0431\u043e\u0438\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445. \u041d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0434\u0430\u0434\u0438\u043c Gender \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0439 \u0442\u0438\u043f Male \u0438 Female, \u0438 \u0432 json \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e Male \u0438 Female. \u0410 Id \u2013 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"cs\">public class User     {         public enum GenderEnum         {             Male,             Female         }          public int Id { get; set; }          public string Name { get; set; }          public string FirstName { get; set; }          public string MiddleName { get; set; }          public string LastName { get; set; }          public string UserName { get; set; }          public GenderEnum Gender { get; set; }          public string Email { get; set; }     } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"cs\">var user = new User()             {                 Id = 404,                 Email = &quot;chernikov@gmail.com&quot;,                 UserName = &quot;rollinx&quot;,                 Name = &quot;Andrey&quot;,                 FirstName = &quot;Andrey&quot;,                 MiddleName = &quot;Alexandrovich&quot;,                 LastName = &quot;Chernikov&quot;,                 Gender = User.GenderEnum.Male             };              var jsonUser = JsonConvert.SerializeObject(user); <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"javascript\">{&quot;Id&quot;:404,&quot;Name&quot;:&quot;Andrey&quot;,&quot;FirstName&quot;:&quot;Andrey&quot;,&quot;MiddleName&quot;:&quot;Alexandrovich&quot;,&quot;LastName&quot;:&quot;Chernikov&quot;,&quot;UserName&quot;:&quot;rollinx&quot;,&quot;Gender&quot;:0,&quot;Email&quot;:&quot;chernikov@gmail.com&quot;} <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c:  <\/p>\n<pre><code class=\"cs\">[JsonConverter(typeof(StringEnumConverter))]         public enum GenderEnum          {             Male,             Female         } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"javascript\">{&quot;Id&quot;:404,&quot;Name&quot;:&quot;Andrey&quot;,&quot;FirstName&quot;:&quot;Andrey&quot;,&quot;MiddleName&quot;:&quot;Alexandrovich&quot;,&quot;LastName&quot;:&quot;Chernikov&quot;,&quot;UserName&quot;:&quot;rollinx&quot;,&quot;Gender&quot;:&quot;Male&quot;,&quot;Email&quot;:&quot;chernikov@gmail.com&quot;} <\/code><\/pre>\n<p>  \u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435. \u041e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u2013 \u0432\u0441\u0451 \u043e\u043a. \u0418\u0437\u0443\u0447\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u0442\u043e\u043d\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 json-\u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u043d\u0430 \u0432 \u0432\u0435\u043d\u0433\u0435\u0440\u0441\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0438\u043f\u0430 first_name:  <\/p>\n<pre><code class=\"cs\">[JsonObject]     public class User     {         [JsonConverter(typeof(StringEnumConverter))]         public enum GenderEnum          {             Male,             Female         }          [JsonProperty(&quot;id&quot;)]         public int Id { get; set; }          [JsonProperty(&quot;name&quot;)]         public string Name { get; set; }          [JsonProperty(&quot;first_name&quot;)]         public string FirstName { get; set; }          [JsonProperty(&quot;middle_name&quot;)]         public string MiddleName { get; set; }          [JsonProperty(&quot;last_name&quot;)]         public string LastName { get; set; }          [JsonProperty(&quot;user_name&quot;)]         public string UserName { get; set; }          [JsonProperty(&quot;gender&quot;)]         public GenderEnum Gender { get; set; }          [JsonProperty(&quot;email&quot;)]         public string Email { get; set; }     }  <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:   <\/p>\n<pre><code class=\"javascript\">{&quot;id&quot;:404,&quot;name&quot;:&quot;Andrey&quot;,&quot;first_name&quot;:&quot;Andrey&quot;,&quot;middle_name&quot;:&quot;Alexandrovich&quot;,&quot;last_name&quot;:&quot;Chernikov&quot;,&quot;user_name&quot;:&quot;rollinx&quot;,&quot;gender&quot;:&quot;Male&quot;,&quot;email&quot;:&quot;chernikov@gmail.com&quot;} <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Photo:  <\/p>\n<pre><code class=\"cs\">[JsonObject]     public class Photo     {         [JsonProperty(&quot;id&quot;)]         public int Id { get; set; }          [JsonProperty(&quot;name&quot;)]         public string Name { get; set; }     } <\/code><\/pre>\n<p>  \u0418 \u0432 User \u0434\u043e\u0431\u0430\u0432\u0438\u043c:  <\/p>\n<pre><code class=\"cs\">[JsonProperty(&quot;photo_album&quot;)] public List&lt;Photo&gt; PhotoAlbum { get; set; } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:   <\/p>\n<pre><code class=\"javascript\">{&quot;id&quot;:404,&quot;name&quot;:&quot;Andrey&quot;,&quot;first_name&quot;:&quot;Andrey&quot;,&quot;middle_name&quot;:&quot;Alexandrovich&quot;,&quot;last_name&quot;:&quot;Chernikov&quot;,&quot;user_name&quot;:&quot;rollinx&quot;,&quot;gender&quot;:&quot;Male&quot;,&quot;email&quot;:&quot;chernikov@gmail.com&quot;,&quot;photo_album&quot;:[{&quot;id&quot;:1,&quot;name&quot;:&quot;\u042f \u0441 \u0438\u043d\u0441\u0442\u0430\u0433\u0440\u0430\u043c\u043c\u043e\u043c&quot;},{&quot;id&quot;:2,&quot;name&quot;:&quot;\u042f \u043d\u0430 \u0444\u043e\u043d\u0435 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0430\u0437\u0430&quot;}]} <\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<br \/>  \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0434\u043b\u044f Gender \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0435 Male\\Female, \u0430 M\\F. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0443 GenderEnumConverter:  <\/p>\n<pre><code class=\"cs\">public class GenderEnumConverter : JsonConverter     {         public override object ReadJson(JsonReader reader,              Type objectType,             object existingValue,              JsonSerializer serializer)         {             var value = reader.Value.ToString();             if (string.Compare(value, &quot;M&quot;, true) == 0)             {                 return User.GenderEnum.Male;             }             if (string.Compare(value, &quot;F&quot;, true) == 0)             {                 return User.GenderEnum.Female;             }             return  User.GenderEnum.Male;         }          public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)         {             var obj = (User.GenderEnum)value;              \/\/ Write associative array field name             writer.WriteValue(value.ToString().Substring(0,1));         }          public override bool CanConvert(Type objectType)         {             return false;         }     } <\/code><\/pre>\n<p>  \u0418 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438  <\/p>\n<pre><code class=\"cs\">[JsonConverter(typeof(GenderEnumConverter))]         public enum GenderEnum          {             Male,             Female         } <\/code><\/pre>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 json-\u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u0442, \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0432\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<h5>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 facebook<\/h5>\n<p>  \u0412\u0441\u0451 \u044d\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438 \u0441\u043a\u0443\u0447\u043d\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u0435\u0442\u043d\u0435\u043c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 facebook API. \u0420\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0439 \u0432\u0441\u0435\u043c! \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 LessonProject.FacebookAPI. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0443\u0434\u0430 Json.NET \u0438 \u0441\u0432\u044f\u0436\u0435\u043c \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c. <\/p>\n<p>  \u041d\u0430 facebook \u043d\u0430\u0434\u043e \u0437\u0430\u0432\u0435\u0441\u0442\u0438 ApplicationID \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443:<br \/>  <a href=\"https:\/\/developers.facebook.com\/apps\">https:\/\/developers.facebook.com\/apps<\/a><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/65b\/3d3\/c73\/65b3d3c739c963cbcd1e766a3bbad20d.jpg\"\/><\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c: <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/42f\/cb2\/162\/42fcb21629b2f905e5c139d196bd8add.jpg\"\/><\/p>\n<p>  \u041d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0431\u0443\u0434\u0435\u0442 AppID \u0438 AppSecret. <br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Config\/FacebookSetting.cs (\u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f):  <\/p>\n<pre><code class=\"cs\"> public class FacebookSetting : ConfigurationSection     {         [ConfigurationProperty(&quot;AppID&quot;, IsRequired = true)]         public string AppID         {             get             {                 return this[&quot;AppID&quot;] as string;             }             set             {                 this[&quot;AppID&quot;] = value;             }         }          [ConfigurationProperty(&quot;AppSecret&quot;, IsRequired = true)]         public string AppSecret         {             get             {                 return this[&quot;AppSecret&quot;] as string;             }             set             {                 this[&quot;AppSecret&quot;] = value;             }              }  } <\/code><\/pre>\n<p>  \u041e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u0444\u0435\u0439\u0441\u0431\u0443\u043a\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<ul>\n<li>\u041f\u043e\u043f\u0440\u043e\u0441\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c<\/li>\n<li>\u041e\u0442\u0432\u0435\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043f\u043e \u043d\u0435\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/li>\n<\/ul>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448 FacebookSetting (\u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c) (LessonProject.FacebookAPI\/IFbAppConfig.cs):  <\/p>\n<pre><code class=\"cs\">public interface IFbAppConfig     {         string AppID { get; }          string AppSecret { get; }     } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 FacebookSetting (\/Global\/Config\/FacebookSetting.cs):  <\/p>\n<pre><code class=\"cs\">public class FacebookSetting : ConfigurationSection, IFbAppConfig <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0430\u0448 AppID, \u043c\u044b \u0438\u0434\u0435\u043c \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0435 \u0442\u0438\u043f\u0430:  <\/p>\n<pre><code>https:\/\/www.facebook.com\/dialog\/oauth?client_id=136398216534301&redirect_uri=http%3A%2F%2Flocalhost%3A54484%2FFacebook%2FToken&scope=email  <\/code><\/pre>\n<p>  \u0418 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d9e\/e2e\/c5f\/d9ee2ec5fbcfc88463e31f6e601fbe65.jpg\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u00ab\u041f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e\u00bb \u2014 \u0442\u043e \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 <br \/>  <code>http:\/\/localhost:54484\/Facebook\/Token<\/code> \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c code, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f). \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:  <\/p>\n<pre><code>https:\/\/graph.facebook.com\/oauth\/access_token?client_id=136398216534301&redirect_uri=http:\/\/localhost:54484\/Facebook\/Token&client_secret=e6de78fd40596f00e225dce861b34a1a&code=AQAScKUYKGpzwijzT3Y3SHjNOd4Q5nsyrYPdJaPhX-88r-wBOuMrdimL8h82bGv3HAh7TL6oJyZ0gNgiB8BcCeH8G_Zj7h6hlft_BFbOfIJIZJB9nKW6Q4iR3a0VVImxM0QYJas3eVg4qtYNkqUcWbgXDSK2JENcuomUX38haxFUFdKXrVjL1acNZSocESsx6nfx_FyF_QlbwnUO5cwogrLp <\/code><\/pre>\n<p>  \u041d\u0430 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442:  <\/p>\n<pre><code>access_token=AAAB8Da8ZBmR0BAMCOx5293ZArYvFu5oRkmZCrwZAbvpWZB3ZCLBeiooslyYPZBVwHjxSpe3KzJ4VLFPIxwwf0D6TIEiM5ApzU8EMoDpOxE4uAZDZD&expires=5183977 <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u044d\u0442\u043e\u0442 access_token, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435:  <\/p>\n<pre><code>https:\/\/graph.facebook.com\/me?access_token=AAAB8Da8ZBmR0BAImiTO9QwuUXbgHPLZBQWmAyZBUkjR2A37aVNs4vaqaFmt6h1ZBvurUpvN95EXddy5d6J1ldZA2jWTxSd3eZBHlYMzKwdxgZDZD <\/code><\/pre>\n<p>  \u041d\u0430 \u0447\u0442\u043e \u043e\u043d \u043d\u0430\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442:  <\/p>\n<pre><code class=\"javascript\">{&quot;id&quot;:&quot;708770020&quot;,&quot;name&quot;:&quot;Andrey Chernikov&quot;,&quot;first_name&quot;:&quot;Andrey&quot;,&quot;last_name&quot;:&quot;Chernikov&quot;,&quot;link&quot;:&quot;http:\\\/\\\/www.facebook.com\\\/chernikov1&quot;,&quot;username&quot;:&quot;chernikov1&quot;,&quot;gender&quot;:&quot;male&quot;,&quot;email&quot;:&quot;chernikov\\u0040gmail.com&quot;,&quot;timezone&quot;:2,&quot;locale&quot;:&quot;ru_RU&quot;,&quot;verified&quot;:true,&quot;updated_time&quot;:&quot;2013-03-06T15:01:28+0000&quot;} <\/code><\/pre>\n<p>  \u0418 \u0432\u043e\u0442 \u044d\u0442\u043e \u043c\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a \u043a\u043b\u0430\u0441\u0441\u0443 FbUserInfo (LessonProject.FacebookAPI\/FbUserInfo.cs):  <\/p>\n<pre><code class=\"cs\">[JsonObject]     public class FbUserInfo     {         [JsonProperty(&quot;id&quot;)]         public string Id { get; set; }          [JsonProperty(&quot;name&quot;)]         public string Name { get; set; }          [JsonProperty(&quot;first_name&quot;)]         public string FirstName { get; set; }          [JsonProperty(&quot;last_name&quot;)]         public string LastName { get; set; }          [JsonProperty(&quot;link&quot;)]         public string Link { get; set; }          [JsonProperty(&quot;username&quot;)]         public string UserName { get; set; }          [JsonProperty(&quot;gender&quot;)]         public string Gender { get; set; }          [JsonProperty(&quot;email&quot;)]         public string Email { get; set; }          [JsonProperty(&quot;locale&quot;)]         public string Locale { get; set; }          [JsonProperty(&quot;timezone&quot;)]         public double? Timezone { get; set; }          [JsonProperty(&quot;verified&quot;)]         public bool? Verified { get; set; }          [JsonProperty(&quot;updated_time&quot;)]         public DateTime? updatedTime { get; set; }      } <\/code><\/pre>\n<p>  \u0412\u0441\u044e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432 FbProvider.cs (LessonProject.FacebookAPI\/Provider.cs):  <\/p>\n<pre><code class=\"cs\">public class FbProvider     {         private static string AuthorizeUri = &quot;https:\/\/graph.facebook.com\/oauth\/authorize?client_id={0}&redirect_uri={1}&scope=email&quot;;         private static string GetAccessTokenUri = &quot;https:\/\/graph.facebook.com\/oauth\/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}&quot;;         private static string GetUserInfoUri = &quot;https:\/\/graph.facebook.com\/me?access_token={0}&quot;;          private static string GraphUri = &quot;https:\/\/graph.facebook.com\/{0}&quot;;          public IFbAppConfig Config { get; set; }          public string AccessToken { get; set; }          public string Authorize(string redirectTo)         {             return string.Format(AuthorizeUri, Config.AppID, redirectTo);         }          public bool GetAccessToken(string code, string redirectTo)         {             var request = string.Format(GetAccessTokenUri, Config.AppID, redirectTo, Config.AppSecret, code);             WebClient webClient = new WebClient();             string response = webClient.DownloadString(request);             try             {                 var pairResponse = response.Split('&');                 AccessToken = pairResponse[0].Split('=')[1];                 return true;             }             catch (Exception ex)             {                 return false;             }         }          public JObject GetUserInfo()         {             var request = string.Format(GetUserInfoUri, AccessToken);             WebClient webClient = new WebClient();              string response = webClient.DownloadString(request);             return JObject.Parse(response);         }     }  <\/code><\/pre>\n<p>  \u0413\u0434\u0435  <\/p>\n<ul>\n<li><b>Authorize<\/b> \u2013 \u044d\u0442\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0430\u0432. <\/li>\n<li><b>GetAccessToken<\/b> \u2013 \u044d\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430.<\/li>\n<li><b>GetUserInfo<\/b> \u2013 \u044d\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<\/ul>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>WebClient.DownloadString<\/code> \u2013 \u0438 \u043e\u043f-\u043f\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043d\u0435\u0434\u0440 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430. <\/p>\n<p>  \u0415\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 FacebookController (\/Areas\/Default\/Controllers\/FacebookController.cs):  <\/p>\n<pre><code class=\"cs\">public class FacebookController : DefaultController     {         private FbProvider fbProvider;          protected override void Initialize(System.Web.Routing.RequestContext requestContext)         {             fbProvider = new FbProvider();             fbProvider.Config = Config.FacebookSetting;             base.Initialize(requestContext);         }          public ActionResult Index()         {             return Redirect(fbProvider.Authorize(&quot;http:\/\/&quot; + HostName + &quot;\/Facebook\/Token&quot;));         }          public ActionResult Token()         {             if (Request.Params.AllKeys.Contains(&quot;code&quot;))             {                 var code = Request.Params[&quot;code&quot;];                 if (fbProvider.GetAccessToken(code, &quot;http:\/\/&quot; + HostName + &quot;\/Facebook\/Token&quot;))                 {                     var jObj = fbProvider.GetUserInfo();                     var fbUserInfo = JsonConvert.DeserializeObject&lt;FbUserInfo&gt;(jObj.ToString());                      return View(fbUserInfo);                 }                              }             return View(&quot;CantInitialize&quot;);         }      }  <\/code><\/pre>\n<p>  \u0412 Initialize \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 <code>FbProvider<\/code> <code>AppID<\/code>\u0438 <code>AppSecret<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0445\u043e\u0434\u0430 \u2013 \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u043d\u0430 facebook \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043f\u0440\u0430\u0432 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043e\u043a\u043e\u0448\u043a\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f). \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u043d\u0430\u043c \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u043e 100 \u0440\u0430\u0437, facebook \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u0438\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \/Facebook\/Token. \u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c View CantInitialize (\/Areas\/Default\/Views\/Facebook\/CantInitialize.cshtml):  <\/p>\n<pre><code class=\"html\">@{     ViewBag.Title = &quot;CantInitialize&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;CantInitialize&lt;\/h2&gt;  &lt;h3&gt; \u041d\u0443 \u043d\u0435\u0442 - \u0442\u0430\u043a \u043d\u0435\u0442&lt;\/h3&gt; <\/code><\/pre>\n<p>  \u0418\u043d\u0430\u0447\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0430\u0448 \u0442\u043e\u043a\u0435\u043d (\u043e\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 fbProvider) \u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u2013 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 FbUserInfo \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u043e View (\/Areas\/Default\/Views\/Facebook\/Token.cshtml):  <\/p>\n<pre><code class=\"html\">@model LessonProject.FacebookAPI.FbUserInfo  @{     ViewBag.Title = &quot;Token&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;\u0414\u0430\u043d\u043d\u044b\u0435&lt;\/h2&gt; &lt;p&gt; \u0412\u043e\u0442 \u0447\u0442\u043e \u044f \u043f\u0440\u043e \u0442\u0435\u0431\u044f \u0437\u043d\u0430\u044e:&lt;\/p&gt;  &lt;dl class=&quot;dl-horizontal&quot;&gt;     &lt;dt&gt;ID&lt;\/dt&gt;     &lt;dd&gt;@Model.Id&lt;\/dd&gt;          &lt;dt&gt;FirstName&lt;\/dt&gt;     &lt;dd&gt;@Model.FirstName&lt;\/dd&gt;     &lt;dt&gt;LastName&lt;\/dt&gt;     &lt;dd&gt;@Model.LastName&lt;\/dd&gt;     &lt;dt&gt;Link&lt;\/dt&gt;     &lt;dd&gt;@Model.Link&lt;\/dd&gt; &lt;\/dl&gt; <\/code><\/pre>\n<h5>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434\/\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 (Access-Control-Allow-Origin)<\/h5>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u0432 js-\u0444\u0430\u0439\u043b\u0430\u0445, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0418\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 Token. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u043e\u0442 facebook, \u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432\u043e View \u0442\u043e\u043a\u0435\u043d (\/Areas\/Default\/Controllers\/FacebookController.cs:Token):  <\/p>\n<pre><code class=\"cs\">public ActionResult Token()         {             if (Request.Params.AllKeys.Contains(&quot;code&quot;))             {                 var code = Request.Params[&quot;code&quot;];                 if (fbProvider.GetAccessToken(code, &quot;http:\/\/&quot; + HostName + &quot;\/Facebook\/Token&quot;))                 {                   \/*   var jObj = fbProvider.GetUserInfo();                     var fbUserInfo = JsonConvert.DeserializeObject&lt;FbUserInfo&gt;(jObj.ToString());                     *\/                     ViewBag.Token = fbProvider.AccessToken;                     return View();                 }                              }             return View(&quot;CantInitialize&quot;);         }  <\/code><\/pre>\n<p>  \u0418\u0437\u043c\u0435\u043d\u0438\u043c Token.cshtml (\/Areas\/Default\/Views\/Facebook\/Token.cshtml):  <\/p>\n<pre><code class=\"html\">@{     ViewBag.Title = &quot;Token&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;; } @section scripts {     @Scripts.Render(&quot;~\/Scripts\/default\/facebook-token.js&quot;) }  @Html.Hidden(&quot;Token&quot;, ViewBag.Token as string) &lt;h2&gt;\u0414\u0430\u043d\u043d\u044b\u0435&lt;\/h2&gt; &lt;p&gt; \u0412\u043e\u0442 \u0447\u0442\u043e \u044f \u043f\u0440\u043e \u0442\u0435\u0431\u044f \u0437\u043d\u0430\u044e:&lt;\/p&gt;  &lt;dl class=&quot;dl-horizontal&quot;&gt;     &lt;dt&gt;ID&lt;\/dt&gt;     &lt;dd id=&quot;ID&quot;&gt;&lt;\/dd&gt;          &lt;dt&gt;FirstName&lt;\/dt&gt;     &lt;dd id=&quot;FirstName&quot;&gt;&lt;\/dd&gt;     &lt;dt&gt;LastName&lt;\/dt&gt;     &lt;dd id=&quot;LastName&quot;&gt;&lt;\/dd&gt;     &lt;dt&gt;Link&lt;\/dt&gt;     &lt;dd id=&quot;Link&quot;&gt;&lt;\/dd&gt; &lt;\/dl&gt; <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c facebook-token.js (\/Scripts\/default\/facebook-token.js):  <\/p>\n<pre><code class=\"javascript\">function FacebookToken() {     _this = this;      this.ajaxGetUserInfo = &quot;https:\/\/graph.facebook.com\/me?access_token=&quot;;      this.init = function () {         var token = $(&quot;#Token&quot;).val();         $.ajax({             type: &quot;GET&quot;,             dataType: 'json',             url: _this.ajaxGetUserInfo + token,             success: function (data)             {                 $(&quot;#ID&quot;).text(data.id);                 $(&quot;#FirstName&quot;).text(data.first_name);                 $(&quot;#LastName&quot;).text(data.last_name);                 $(&quot;#Link&quot;).text(data.link);             }         })     } }  var facebookToken = null;  $().ready(function () {     facebookToken = new FacebookToken();     facebookToken.init(); }); <\/code><\/pre>\n<p>  \u2003<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c. \u0412\u0441\u0451 \u043e\u0442\u043b\u0438\u0447\u043d\u043e. \u041d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 http-\u043e\u0442\u0432\u0435\u0442\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3b4\/8ae\/b5e\/3b48aeb5ee8abb6a21c088f3edd48675.jpg\"\/><\/p>\n<p>  Access-control-allow-origin \u2013 \u044d\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0431\u0443\u0434\u0443\u0447\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043a \u0441\u0430\u0439\u0442\u0443, \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0434\u043e\u043c\u0435\u043d\u0435.<br \/>  \u0422.\u0435. \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043f\u043e $.ajax() \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043d\u0435\u0442, \u0442\u043e \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430:<br \/>  <code>Origin http:\/\/localhost:8080 is not allowed by Access-Control-Allow-Origin<\/code><br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0441\u0430\u0439\u0442\u0443 \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 (\/Attribute\/AllowCrossSiteJson.cs):  <\/p>\n<pre><code class=\"cs\">public class AllowCrossSiteJsonAttribute : ActionFilterAttribute     {         public override void OnActionExecuting(ActionExecutingContext filterContext)         {             filterContext.RequestContext.HttpContext.Response.AddHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);             base.OnActionExecuting(filterContext);         }     } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u0430\u043f\u0438\u043c\u0435\u0440, \u043c\u0435\u0442\u043e\u0434-action OK, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c { \u201cresult\u201d: \u201cOK\u201d} (\/Areas\/Default\/Controllers\/HomeController.cs):  <\/p>\n<pre><code class=\"cs\">[AllowCrossSiteJson]         public ActionResult OK()         {             return Json(new { result = &quot;OK&quot; }, JsonRequestBehavior.AllowGet);         } <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451 \u043f\u043e Json \u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 facebook. \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0441 vk api. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0442\u0443\u0442: <a href=\"http:\/\/vk.com\/developers.php\">http:\/\/vk.com\/developers.php<\/a>.<\/p>\n<p>  \u0412\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/bitbucket.org\/chernikov\/lessons\">https:\/\/bitbucket.org\/chernikov\/lessons<\/a>    \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\/176087\/\"> http:\/\/habrahabr.ru\/post\/176087\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430.<\/b> \u041d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c json. \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 json. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 facebook \u0438 vkontakte. Ajax \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 json (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c). API \u0441\u0430\u0439\u0442\u0430.<\/p>\n<h5>Json \u0438 Json.net<\/h5>\n<p>  Json \u2013 \u044d\u0442\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Javascript. <br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Json:  <\/p>\n<pre><code class=\"javascript\">{             &quot;firstName&quot;: &quot;\u0418\u0432\u0430\u043d&quot;,             &quot;lastName&quot;: &quot;\u0418\u0432\u0430\u043d\u043e\u0432&quot;,             &quot;address&quot;: {                 &quot;streetAddress&quot;: &quot;\u041c\u043e\u0441\u043a\u043e\u0432\u0441\u043a\u043e\u0435 \u0448., 101, \u043a\u0432.101&quot;,                 &quot;city&quot;: &quot;\u041b\u0435\u043d\u0438\u043d\u0433\u0440\u0430\u0434&quot;,                 &quot;postalCode&quot;: 101101             },    &quot;phoneNumbers&quot;: [        &quot;812 123-1234&quot;,        &quot;916 123-4567&quot;    \t]   } <\/code><\/pre>\n<p>  <\/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-176087","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176087","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=176087"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176087\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}