Showing posts with label uploads. Show all posts
Showing posts with label uploads. Show all posts

Wednesday, March 21, 2012

Permissions Help with asp.net saving uploaded files

I have a function that uploads a file to a specific directory, making the
directory if it doesn't already exist.

This works, unless I try to upload a file to a pre-existing directory. If I
do that, I get this vague error:

Exception has been thrown by the target of an invocation.

From what I can tell, this is maybe a permissions issue?

'aspnet_wp account' has full control over the parent directory and any
directory it makes. The only oddity is that upon first creation of a
directory, I get prompted by the browser to enter my own network
username/pwd.

I'm completely stuck on this and really have no idea what to check for. Is
there anyway to get a more specific error message out of the application
than the one above?

-Darrel> I'm completely stuck on this and really have no idea what to check for. Is
> there anyway to get a more specific error message out of the application
> than the one above?

Aha. I figured that part out:

exc.InnerException.Message

Which gives me a much more specific answer...access denied for the
particular directory I'm trying to save to.

So, what should I check for? What is odd is that my application is just fine
creating the directory and then immediately uploading some files to it. It's
only on subsequent attempts does it get the access deined error.

-Darrel

Permissions needed for user to upload file to an App_Data subfolder

I saw a recent note here that user file uploads should be directed to a
subfolder of App_Data to avoid site recompilation each time a file is
uploaded. That worked fine on my development machine, but when I deployed to
a test site at my web host, it fails:
Access to the path '...\App_Data\PDFFiles\Filename.pdf' is denied.
How do I set permissions to allow writing a file into that folder? Is this
something I do in my page or site configuration, or do I need to contact the
web hosting company?This is usually done through the web host or their control panel. IIS is
giving the error because the directory permissions set don't enable the
ASP.Net (or sometimes another account such as Network Services depending
upon the windows server version) user account to write to the directory. So
yes, you'll need to start with the host. There may be an automated way to do
this in the control panel so check there first.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
"Paul Shapiro" <paul@.hideme.broadwayData.com> wrote in message
news:%23PwJ2hmgIHA.4396@.TK2MSFTNGP04.phx.gbl...
>I saw a recent note here that user file uploads should be directed to a
>subfolder of App_Data to avoid site recompilation each time a file is
>uploaded. That worked fine on my development machine, but when I deployed
>to a test site at my web host, it fails:
> Access to the path '...\App_Data\PDFFiles\Filename.pdf' is denied.
> How do I set permissions to allow writing a file into that folder? Is this
> something I do in my page or site configuration, or do I need to contact
> the web hosting company?
Thank you Mark. Folder permissions were not accessible in the web host's
control panel. I sent an email request and they added the permissions for
the web account. It's working now.
"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eopxMJ8gIHA.2448@.TK2MSFTNGP03.phx.gbl...
> This is usually done through the web host or their control panel. IIS is
> giving the error because the directory permissions set don't enable the
> ASP.Net (or sometimes another account such as Network Services depending
> upon the windows server version) user account to write to the directory.
> So yes, you'll need to start with the host. There may be an automated way
> to do this in the control panel so check there first.
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - Expression
> "Paul Shapiro" <paul@.hideme.broadwayData.com> wrote in message
> news:%23PwJ2hmgIHA.4396@.TK2MSFTNGP04.phx.gbl...