{"id":706,"date":"2023-07-14T16:06:13","date_gmt":"2023-07-14T07:06:13","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=706"},"modified":"2023-07-14T16:08:32","modified_gmt":"2023-07-14T07:08:32","slug":"blazor-serverside%e3%81%a7%e3%81%ae%e3%82%bb%e3%83%83%e3%82%b7%e3%83%a7%e3%83%b3%e5%a4%89%e6%95%b0","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=706","title":{"rendered":"blazor serverside\u3067\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570"},"content":{"rendered":"\n<p>asp.net blazor server side\u3067\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3092\u4f7f\u304a\u3046\u3068\u3057\u3066\u3001\u30c1\u30e7\u30c3\u30c8\u5d4c\u3063\u305f\u306e\u3067\u3001\u30e1\u30e2\u3002<\/p>\n\n\n\n<p>asp.net webapp\u306a\u3069\u3067\u306f\u3001Program.cs\u4e2d\u3067Service\u306bSession\u3092\u8ffd\u52a0\u3057\u3066\u3001UseSession\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u304b\u3089\u306f\u3001HttpContext.Session\u3092\u4ecb\u3057\u3066\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3092\u6271\u3048\u308b\u304c\u3001blazor server side\u306e\u5834\u5408\u3001HttpContext\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u306e\u304b\u8abf\u3079\u3066\u307f\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3092\u4fdd\u5b58,\u53c2\u7167,\u524a\u9664\u3067\u304d\u308b\u3088\u3046\u3060\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"Blazor Server Side\u3067\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u64cd\u4f5c\" data-lang=\"C#\"><code>@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage\n@inject ProtectedSessionStorage Session\n\u30fb\u30fb\u30fb\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u64cd\u4f5c(\u30ad\u30fc\u306f\u5f53\u7136string)\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3078\u5024\u3092\u4fdd\u5b58(\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306eValue\u306fobject\u578b)\nawait Session.SetAsync(Key,Value);\n\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u304b\u3089\u5024\u3092\u53d6\u5f97\n\/\/ val\u306e\u578b\u306fProtectedBrowserStorageResult&lt;T&gt;\u3068\u306a\u308b\nvar val = await Session.GetAsync&lt;T&gt;(Key);\nif (!val.Success) {\n\t\/\/ \u53d6\u5f97\u5931\u6557\n}\nT? v = val.Value;\n\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3092\u524a\u9664\nawait Session.DeleteAsync(Key);<\/code><\/pre><\/div>\n\n\n\n<p>\u305f\u3060\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u7fa4\u306fJavascript\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3001OnInitializedAsync\u5185\u3067\u547c\u3073\u51fa\u3059\u3068\u3001\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u521d\u671f\u5316\u6642\u306b\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u306e\u5024\u3092\u5f97\u305f\u3044\u5834\u5408\u306f\u3001OnAfterRenderAsync\u4e2d\u306b\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<p>\u666e\u901a\u306bHttpContext\u304c\u53d6\u308c\u308c\u3070\u3044\u3044\u306e\u306b\u30fb\u30fb\u30fb\u307e\u3041\u3001Blazor\u306e\u4ed5\u7d44\u307f\u4e0a\u96e3\u3057\u3044\u306e\u304b\u306a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>asp.net blazor server side\u3067\u30bb\u30c3\u30b7\u30e7\u30f3\u5909\u6570\u3092\u4f7f\u304a\u3046\u3068\u3057 &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=706\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,12,10,9,4],"tags":[],"class_list":["post-706","post","type-post","status-publish","format-standard","hentry","category-net","category-asp-net-core","category-blazor","category-c","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=706"}],"version-history":[{"count":4,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/706\/revisions"}],"predecessor-version":[{"id":741,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/706\/revisions\/741"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}