Search code examples
asp.netauthorizationsecuritywebmatrixcreate-directory

Access denied attempting to create a folder on the server


Every new project that the client registers the system creates a folder to store the images located in "\Images\Projects{ProjectID}" where {ProjectID} is the ID project.

I put in the folder "\Images\Projects\" a web.config to allow access to users logged on.

<configuration>
    <system.web>
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>
</configuration>

When creating the folder, the error is displayed:

Access to the path 'e:\home\amsdarquit\Web\Images\Projects\166' is denied.

166 is the project code, and the folder name. I checked on my server, and the same is not created.

Code to create the folder

//Save Image
var serverPath = Server.MapPath(Href("~/Images/Projects/") + id);
Directory.CreateDirectory(serverPath);
imgOri.Save(Path.Combine(serverPath, fileName));

I have looked on the site, but found nothing to help me.


Solution

  • Check whether 'NETWORK SERVICE' user (or the user that you run your application as) has modification rights for the parent directory on the drive.