ASP.NET: Abort error on access while uploading files

I have a .NET program to upload an image to a web server. For this I am using the ASP.NET File Upload Control. The program works well in my local environment, but when I run it on the web server, I get the following error:

>     System.UnauthorizedAccessException:
> Access to the path
> '\\fsvs02\target03\352972\352974\www.mysite.com\web\content\Images\TempStorage\tempImage.jpg'
> 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)
>        at System.IO.FileStream..ctor(String
> path, FileMode mode)
>        at System.Web.HttpPostedFile.SaveAs(String
> filename)
>        at uploadimage.UploadImage()

      

A quick Google search confirmed it was a permissions issue; but since it only happens intermittently, I don't have a diagnostic plan for how to fix it.

My question is, what should I do to diagnose and fix this problem?

0


source to share


4 answers


Are you uploading the file to the same filename for each user (you can see from the error message that this is the case)? If so, then this is probably what Adi says. Use Path.GetTempFileName instead to create a filename for your temporary file, which won't clash with one that already exists. Be sure to move or delete the file when you're done or you close the hard drive with temporary files.



+2


source


Check if the problem occurs when copying files to production instead of downloading them. The copied files may have more restrictive restrictions that prevent access to the process in which your application is running. When you try to overwrite such a file by uploading another with the same name, the above exception is thrown.



The solution would be to upload files directly through your application and set the required permissions directly to the files you copy from your test env.

0


source


It could also mean that the file was locked by another process. for example, two files with the same name are loaded at the same time. Or, another process is using the file you are trying to overwrite.

0


source


What's not mentioned if your web application is on the public Internet or on a private intranet and uses Windows authentication? In such a situation, it might be the case where users who are allowed (via NTFS permissions) are downloading to this folder while others are not. They are authenticated by their user accounts, not by the anonymous NETWORK SERVICE or other account used for the IIS application pool.

0


source







All Articles