简体   繁体   中英

Allow users Create Folder inside a asp.net website

I am developing a asp.net website. I want to allow users to create their own folders inside the website.

string pathToCreate = "~/path/sub folder";
        if (Directory.Exists(Server.MapPath(pathToCreate)))
        {
            // folder exist message
        }
        else
        { //cerate folder
            Directory.CreateDirectory(Server.MapPath(pathToCreate));
            base.OnLoad(e);
        }

This working when I am debugging using visual studio. But after when I host it in IIS it showing the error of Access denied to the previously specified path

Access to the path 'C:\inetpub\wwwroot\sample_site\resources\users_folder' is denied.

Line 47:                 Directory.CreateDirectory(Server.MapPath(pathToCreate));

By default, write access is not allowed for the ASP.NET process inside the web directory.

There is an exception however. You can write to the App_Data directory. Just create folders inside there.

It needs the whole path - something like "C:\\inetpub\\wwwroot\\sample_site\\resources\\users_folder".

Use Server.MapPath("~/YourApplication/folder") + @"\\folder" to get physical path of the folder.

Referance:

http://forums.asp.net/t/1622617.aspx/1

Either:

  1. Give write permissions to this folder for user that IIS is running under.
  2. Create a new user on the server, give this user write permissions and get the website to impersonate this user by adding to the web.config:

    < identity impersonate="true" userName="username" password="password"/ >

I've always found 2. works better in our environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM