0

I am trying to add a photo upload to my site. I am going to upload to my site prior to storing it long term on Amazon s3.

This is the code I am using:

using (var fs = new FileStream(fullpath, FileMode.Create)) { while (startlength < totalContentLength) { int bytes = FileUpload1.PostedFile.InputStream.Read(buffer, 0, bufferSize); startlength += bytes; fs.Write(buffer, 0, bytes); _percent = Convert.ToInt32(startlength * 100 / totalContentLength / 2); Cache[_processkey] = _percent; } fs.Seek(0, SeekOrigin.Begin); var thumbnailbytes = new byte[fs.Length]; fs.Read(thumbnailbytes, 0, Convert.ToInt32(fs.Length)); thumbnailbytes = GlobalUtilities.ResizeImage(thumbnailbytes, GlobalSettings.CustomerImages.MaxThumbnailImageWidth, GlobalSettings.CustomerImages.MaxThumbnailImageHeight); File.WriteAllBytes(fullpath, thumbnailbytes); } 

I have given access to both Everyone and IIS_USRS to the fullpath directory and I am running Visual Studio 2013 as an administrator. However, when it gets to this line in the code:

using (var fs = new FileStream(fullpath, FileMode.Create)) 

I get an error that

Access to the path 'C:\Users\ME\Documents\Business\Folder\repos\vb\Z\Replicated\Replicated\test\before_b3874a79-1e75-44df-bc47-6940ad4f496e.jpg' is denied.

What am I missing or doing wrong?

I am running VS2013 and debuggin via IIS.

1 Answer 1

1

When you are hosting your application in IIS, this application will run under the identity that's configured for the application pool. Depending on the specific version of Windows and IIS this identity might vary. Here's a good article I invite you to read about application pool identities: http://www.iis.net/learn/manage/configuring-security/application-pool-identities

So, once you have identified the identity under which your application runs, all yo uhave to do is grant this identity write permissions to the C:\Users\ME\Documents\Business\Folder\repos\vb\Z\Replicated\Replicated\test folder and it should work.

This being said, for development purposes it's usually easier to host your application in the built-in development web server (IIS Express) rather than relying on the heavier, full-blown IIS. In this case your application will run under the identity which is used to start Visual Studio with. So starting it as an Administrator usually will solve those kind of problems locally.

But it's a good thing to familiarize and know which specific identity your application is running under and what permissions does it have because when you deploy on production you might hit the same walls.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.