﻿
{"id":10261,"date":"2019-02-03T07:57:41","date_gmt":"2019-02-03T07:57:41","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=10261"},"modified":"2019-02-03T07:57:41","modified_gmt":"2019-02-03T07:57:41","slug":"asp-net-core-access-to-the-path-x-is-denied-hatasi-ve-cozumu","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-core-access-to-the-path-x-is-denied-hatasi-ve-cozumu\/","title":{"rendered":"Asp.NET Core &#8211; &#8216;Access to the path &#8216;X&#8217; is denied&#8217; Hatas\u0131 ve \u00c7\u00f6z\u00fcm\u00fc"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Asp.NET Core temelli bir proje \u00fczerinde geli\u015ftirme yaparken dosya transfer i\u015flemlerinde g\u00f6zden ka\u00e7an basit bir durumdan dolay\u0131 alm\u0131\u015f oldu\u011fum bir hata \u00fczerine siz de\u011ferli okuyucular\u0131m\u0131n ve keza \u015fahsen benim ayn\u0131 olas\u0131 hatayla tekrar kar\u015f\u0131la\u015fma ihtimaline nazaran h\u0131zl\u0131ca \u00e7\u00f6z\u00fcme eri\u015febilmek i\u00e7in hat\u0131rlat\u0131c\u0131 unsur olmas\u0131 dile\u011fiyle konuyla ilgili blo\u011fuma bir not b\u0131rakmak istedim.<\/p>\n<p>Tabi, ilgili hatay\u0131 bir tek Asp.NET Core mimarisinde de\u011fil standart Asp.NET &#8211; MVC veyahut Windows Forms vs. temelli projelerde alman\u0131zda olas\u0131d\u0131r. Nihayetinde g\u00f6zden ka\u00e7\u0131r\u0131lan durum t\u00fcm \u00e7ekirdeklerde ayn\u0131 refleksin verilmesine sebep olacakt\u0131r. Dolay\u0131s\u0131yla buradaki y\u00f6nlendirme .NET Core&#8217;dan daha evrensel bir \u00e7\u00f6z\u00fcm sunacakt\u0131r.<\/p>\n<p>Hatam\u0131za gelirsek e\u011fer;<\/p>\n<blockquote><p><em><strong>Access to the path &#8216;X&#8217; is denied<\/strong><\/em><\/p><\/blockquote>\n<p>\u015feklindedir. Hatta hatam\u0131z\u0131n g\u00f6rsel halinide a\u015fa\u011f\u0131da ele al\u0131rsak e\u011fer;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2019\/02\/Asp.NET-Core-Access-to-the-path-X-is-denied-Hatas\u0131-ve-\u00c7\u00f6z\u00fcm\u00fc.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2019\/02\/Asp.NET-Core-Access-to-the-path-X-is-denied-Hatas\u0131-ve-\u00c7\u00f6z\u00fcm\u00fc.png\" alt=\"Asp.NET Core - &#039;Access to the path &#039;X&#039; is denied&#039; Hatas\u0131 ve \u00c7\u00f6z\u00fcm\u00fc\" width=\"400\" height=\"68\" class=\"aligncenter size-full wp-image-10263\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2019\/02\/Asp.NET-Core-Access-to-the-path-X-is-denied-Hatas\u0131-ve-\u00c7\u00f6z\u00fcm\u00fc.png 400w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2019\/02\/Asp.NET-Core-Access-to-the-path-X-is-denied-Hatas\u0131-ve-\u00c7\u00f6z\u00fcm\u00fc-300x51.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>Bu hata, &#8220;FileStream&#8221; nesnesi \u00fczerinden herhangi bir dosyay\u0131 transfer etmeye \u00e7al\u0131\u015ft\u0131\u011f\u0131m\u0131z zaman muhtemelen g\u00f6zden ka\u00e7an bir durumdan dolay\u0131 meydana gelmektedir.<br \/>\n\u00d6rne\u011fin;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        &#x5B;HttpPost(&quot;&#x5B;action]&quot;)]\r\n        virtual public IActionResult Upload()\r\n        {\r\n            try\r\n            {\r\n                IFormFileCollection files = Request.Form.Files;\r\n                files.ToList().ForEach(file =&gt;\r\n                {\r\n                    if (file.Length &gt; 0)\r\n                        using (FileStream stream = new FileStream(&quot;D:\\&quot;, FileMode.Create))\r\n                        {\r\n                            file.CopyTo(stream);\r\n                        }\r\n                });\r\n                return Ok();\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw ex;\r\n            }\r\n        }\r\n<\/pre>\n<p>yukar\u0131daki kod blo\u011funu ele al\u0131rsak e\u011fer bu olas\u0131 hata bizleri a\u011f\u0131rlayacakt\u0131r.<\/p>\n<p><strong>Neden mi?<\/strong><\/p>\n<p>Asl\u0131nda sorunun cevab\u0131 olduk\u00e7a basit. &#8220;FileStream&#8221; nesnesi verilen dizinin yan\u0131nda \u00fczerinde i\u015flem yap\u0131lacak olan dosyan\u0131n ad\u0131n\u0131nda belirtilmesini istemektedir. \u0130\u015fte sorun sadece bundan ibarettir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        &#x5B;HttpPost(&quot;&#x5B;action]&quot;)]\r\n        virtual public IActionResult Upload()\r\n        {\r\n            try\r\n            {\r\n                IFormFileCollection files = Request.Form.Files;\r\n                files.ToList().ForEach(file =&gt;\r\n                {\r\n                    if (file.Length &gt; 0)\r\n                        using (FileStream stream = new FileStream(Path.Combine(&quot;D:\\&quot;, file.FileName), FileMode.Create))\r\n                        {\r\n                            file.CopyTo(stream);\r\n                        }\r\n                });\r\n                return Ok();\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw ex;\r\n            }\r\n        }\r\n<\/pre>\n<p>Gerekli alanda dosya ad\u0131n\u0131da belirtti\u011fimiz zaman uygulama sorunsuz \u00e7al\u0131\u015fmaya devam edecektir.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Asp.NET Core temelli bir proje \u00fczerinde geli\u015ftirme yaparken dosya transfer i\u015flemlerinde g\u00f6zden ka\u00e7an basit bir durumdan dolay\u0131 alm\u0131\u015f oldu\u011fum bir hata \u00fczerine siz de\u011ferli okuyucular\u0131m\u0131n ve keza \u015fahsen benim ayn\u0131 olas\u0131 hatayla tekrar&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":10242,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2739,2668,2656],"tags":[2741,2679,2704],"class_list":["post-10261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net-core","category-asp-net-core-2","category-asp-net-core-2-mvc","tag-net-core-hata-cozumu","tag-asp-net-core","tag-asp-net-core-hata"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/10261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=10261"}],"version-history":[{"count":8,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/10261\/revisions"}],"predecessor-version":[{"id":10270,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/10261\/revisions\/10270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/10242"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=10261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=10261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=10261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}