1

I have an asp.net project and I am saving selected image to NewUrunler1 file and I am saving image's path in my database. In local, it works without a problem but since I moved my project to my godaddy host, saving method gives an error. Here is my code to save image:

protected void UploadImage()
    {
        try
        {
            HttpPostedFile yuklenecekDosya = FileUploadImage.PostedFile;
            if (yuklenecekDosya != null)
            {
                FileInfo dosyaBilgisi = new FileInfo(yuklenecekDosya.FileName);
                string yuklemeYeri = Server.MapPath("~/Images/NewUrunler1/" + dosyaBilgisi);
                FileUploadImage.SaveAs(Path.Combine(yuklemeYeri));
            }
        }
        catch (Exception e)
        {
            failDiv.Visible = true;
            lblHata.Text = e.ToString();
        }
    }

When I run this I get an error from try catch. Here is the error:

System.UnauthorizedAccessException: Access to the path 'G:\PleskVhosts\ada-crm.com\httpdocs\Images\NewUrunler1\deneme.png' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at CRM.UrunEkle.UploadImage()

I am new in asp.net so sorry if it is an easy question but I searched in web and couldn't solve it. Thank you for your time.

  • The error says that you do not have access to the folder where you are trying to save the files on the server. Is this folder inside the same folder as your website? If not, try to move the savepath there and see if it helps. – andreasnico Feb 24 '16 at 10:49
  • From the error message, you just need to give full permission. You can do it via their control panel or ask them to give full permission for you –  Feb 25 '16 at 08:18

4 Answers4

1

I am not sure about GoDaddy but in a typical IIS hosted environment, you need to ensure that the folder you are attempting to upload to has Write permission applied to it for the User which is associated with the ApplicationPool of the website.

Also, make sure the path exists first. You can do this by checking whether the folders exist and then creating them if they do not.

Arkiliknam
  • 1,805
  • 1
  • 19
  • 35
1

This has nothing to do with ASP.NET as with basic windows security. Someone has set up your website to run under a user which has no right to write into the site.

This MAKES sense from a security point of view. Now call your host support and ask them - how to change this so the user the website process is running under can read/write into a folder ;)

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • Yes I solved the problem and you are absolutely right. It is little embarrassing since I can't even detect what is the actual problem, but I will keep this in my mind. Thank you :) @TomTom – Batuhan Ozdal Feb 24 '16 at 11:43
1

https://www.godaddy.com/help/set-directory-permissions-windows-6481 this is a manual to set write permissions on goddady. hope its helpful. Give write permissions to your app on the folder your code will work

Sujit.Warrier
  • 2,815
  • 2
  • 28
  • 47
0

No problem with your code, there is access problem with Godaddy host. Goto > Virtual Directory > Directory Access Permission and set Full Control to Application pool group

Sanjay Nishad
  • 1,537
  • 14
  • 26