Allow the creation of a directory in a website

Hi,

I am working on a website using VS 2012.  While developing, I am running the website in IIS Express.  My OS is Windows 7.  I ran into a problem when I try to run the following line of code

System.IO.Directory.CreateDirectory(pathName);

Open in new window


I get the following error:

Access to the path '..\Missionaries\31.Testing' is denied.
Exception Details: System.UnauthorizedAccessException: Access to the path '..\Missionaries\31.Testing' is denied.

I think it is a security/permissions problem.  The problem is is that I have not been able to figure out how to grant permissions.  I would really appreciate any help I could get on this.  I realize that the solution may be specific to VS 2012 or IIS Express and that I may run into a permissions problem again when I deploy the site to the production server, but I can live with that for the time being.  Please let me know if you need any more info to assist me in this problem.

Thanks,

Doug
DLAtkinsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
Generally websites are not allowed to created directories.  That would seem to be a bad security practice.
0
DLAtkinsonAuthor Commented:
Does not answer my question, but thanks anyway.  I have a purpose for this.  Once development is complete it will require a login with admin privileges to access the page where the creation will take place.  If you know how to do this then I would like to hear from you, if not it is okay.
0
SStoryCommented:
<link removed - GaryC132 2nd Oct 2013>

I think the IUSR account on your machine will need permissions to created directories. This again is a really bad idea unless on an intranet.

You may also need to fix perms in IIS virtual directory:
http://support.microsoft.com/kb/313075
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

DLAtkinsonAuthor Commented:
I am using IIS Express.  The above links refer to IIS.
0
guru_samiCommented:
Put this line in page_load of one of your page:
Response.Write(WindowsIdentity.Getcurrent().Name);

See what user is it outputting. Then go to your website's physical folder ->RightClick->Properties->Security->Edit->Add the user that you got above -> Give it  all permissions.
0
GaryCommented:
Either you are trying to go out of the root (../)
or there is no write permissions on the parent folder and/or they are not inherited (see guru_sami's comment)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DLAtkinsonAuthor Commented:
I got it to work.  Interestingly enough it was in my code and not in the permissions or IIS Express Server.  But I think the problem was close to what GaryC123 was describing and possibly guru_sami.  My original code was

// Create a folder in the Missionaries directory for this missionary
string folderName = "..//Missionaries";
string subfolderName = missionaryId + "." + ((TextBox)MissionaryDetails.FindControl("LastNameTextBox")).Text;
string pathName = System.IO.Path.Combine(folderName, subfolderName);

System.IO.Directory.CreateDirectory(pathName);

Open in new window


I changed it as follows:

// Create a folder in the Missionaries directory for this missionary
string rootDirectory = Server.MapPath("~");
string folderName = System.IO.Path.Combine(rootDirectory, "Missionaries");
string subfolderName = missionaryId + "." + ((TextBox)MissionaryDetails.FindControl("LastNameTextBox")).Text;
string pathName = System.IO.Path.Combine(folderName, subfolderName);

System.IO.Directory.CreateDirectory(pathName);

Open in new window


This worked.  If anyone could explain why the second block of code worked and the first did not I would love to hear it.  I imagine pathName in the call

System.IO.Directory.CreateDirectory(pathName);

was not being interpreted the way I thought it was.
0
DLAtkinsonAuthor Commented:
I think both solutions were equally good, but I had to pick one as the best solution.  I appreciate that the solutions were not just links out to other forums.
0
GaryCommented:
Hard to say for definite but in the second code block you are defining the route to Missionaries as a definitive path.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.