Search code examples
c#asp.netcreate-directorydirectory-permissions

CreateDirectory at server in a shared machine


I have an ASP.NET application running over a shared .NET server. I want to allow the current logged user to create a folder into a specific path when the application needs it. So, I'm just checking the following:

var userFolderPath = Path.Combine(Server.MapPath("~/storedphotos"), username);
if (!Directory.Exists(userFolderPath)) {
    Directory.Create(userFolderPath);
}

When I run this code into my local machine it works perfectly. However, when I publish the application to that server and try to do the same, it's returning me:

"Access to the path 'xxxxxx' is denied."

I think it could be a permission issue. Once I cannot change anything at the IIS into the server or any configuration, is there a way to let the user is using my application to create the folder without problems?


Solution

  • try this:

    "Access to the path 'xxxxxx' is denied."

    As Error says You need to assign Permissions to Folders

    1. Right Click Folder
    2. Go to Security Tab
    3. Click on Edit
    4. Click on Add
    5. Click on Addvance
    6. Find Now
    7. Give Permission to IIS_IUSRS (Full Control)
    8. Click On OK
    9. Click On OK
    10. Click On Full Control in allow
    11. Click On OK
    12. Again Run the Application

    Note: If Above things are not working then try to give same permission to NETWORK,NETWORK SERVICE Users