Reputation: 45
I'm currently developing a website application and one of its features is to be able to upload and download the files. All the uploaded files will be stored in the external network location. First is on page load, it will create a temporary folder and all of the uploaded files will be stored there. Then when they click the save button, it will create a folder where it will be permanently stored and put all the files in the folder and remove automatically remove the temporary folder. It is working fine in my local host server, but when I upload it and put to web server, it throws an error, Access to the path '(network path)' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
I've researched for a solution for almost a week now and it says it's something about permission, but all of the solutions on the net are not clear and doesn't work for me. I hope someone could help me with the step by step instruction on how to configure permissions to be able to allow network access o any possible working solutions.
UPDATE: Here is the current screenshot:
I hae downloaded the ASP.NET components but I can't find the ASP.NET account. I have .net 4.0 application pool. Should I give permission on my uploading folder? Please help me.
Thank you everyone.
Upvotes: 3
Views: 27507
Reputation: 11
Just a hint: in my case, the following code doesn't work and emits the message “Access to the path (...) is denied.”
var Request = HttpContext.Current.Request;
foreach (string file in Request.Files)
{
var postedFile = Request.Files[file];
postedFile.SaveAs(pathToSave);
}
This one works fine:
var Request = HttpContext.Current.Request;
foreach (string file in Request.Files)
{
var postedFile = Request.Files[file];
using (var stream = new FileStream(pathToSave, FileMode.Create))
{
await postedFile.InputStream.CopyToAsync(stream);
}
}
Upvotes: 0
Reputation: 3649
Fixed mine by:
properties
security
tab click add
IIS_IUSRS
and then click Check Names
OK
and grant full-access
from the permissions categoryIf you cant find
IIS_IUSRS
you can always go toSecurity > Add > Advanced > Find Now
to find the IIS username.
I've also added the current logged in user by typing in the current logged in username
and granted full-access
Upvotes: 1
Reputation: 143
In my case , i just copied required files to wwwroot folder in c Drive, and changed the physical path , it solved my issue.
Upvotes: 0
Reputation: 440
I struggled with this same issue and while we did all the permission changes shown I was still getting the error. In the end I wrote a small test page using the file upload control and when I tried it with various files it worked fine.
What I discovered was that there was a slight difference between these two file names and that was causing the error
Yes, the underscore was causing the access violation error and for the life of me I do not know why? This also applies to files with a space in the file name. We are running the webserver (IIS7) on a Windows Server 2012 R2 if that makes a difference.
I did not find any reference to this in the control though it will fail on long file names as well.
Upvotes: 1
Reputation: 2978
This is a permission issue and you already have a hint :
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Upvotes: 6