Ask a Question related to ASP.NET Security, Design and Development.
-
John #1
Create Directory
Hello,
I am having a permissions problem when creating a directory. The relevant
bits of my code look like this:
// impersonate current user:
WindowsIdentity ident = (WindowsIdentity)
HttpContext.Current.User.Identity;
_context = ident.Impersonate();
_name = ident.Name;
_isauth = ident.IsAuthenticated;
_authtype = ident.AuthenticationType;
// create the directory
// I've also tried using DirectoryInfo.Create()
Directory.CreateDirectory(directoryName);
// restore current (aspnet) identity:
_context.Undo();
If "directoryname" is "e:\inetpub\wwwroot\unittests\createdirectory\ New" I
am getting the error Could not find a part of the path "e:\".
If I grant this user access to the root of my "e" drive then it works
fine. However, doing this is a security risk (and also, to me, seems
completely unnecessary).
Does anyone know why this happens and if there is a sensible way round
it? Is this a .net bug?
Any help would be very much appreciated as I am completely stumped!
Thanks,
John
John Guest
-
Cannot create directory
Hey, I am trying to install contribute cs3 for a client. I am having trouble setting up the connection to their company website. Once I put... -
change into a directory to create other folders/directory
I need to create sub folders in a parent folder.. i have ... <cfset session.parentdir = "e:\mainstuff\"> <cfdirectory action="create"... -
How would I create a directory in ASP.NET?
I've got a permission issue when I try to create a folder programmatically using C# in an ASP.NET web service. I've set ASP.NET user to have full... -
can't create directory from web service
Using the Directory object I issue a createdirectory command and get an exception: System.IO.DirectoryNotFoundException: Could not find a part of... -
How to create a new Virtual Directory?
I have bought an asp.net host,but there is only one Virtual Directory. How to create a new Virtual Directory in an ASP.NET application? Thanks! -
John #2
Re: Create Directory
Is the only way round this really to grant read directory permissions for> I am having a permissions problem when creating a directory. The
> relevant bits of my code look like this:
>
> <<SNIPPED>>
>
> If "directoryname" is "e:\inetpub\wwwroot\unittests\createdirectory\ New"
> I am getting the error Could not find a part of the path "e:\".
>
> If I grant this user access to the root of my "e" drive then it works
> fine. However, doing this is a security risk (and also, to me, seems
> completely unnecessary).
>
> Does anyone know why this happens and if there is a sensible way round
> it? Is this a .net bug?
the user on the root of the drive?
This seems very odd to me. Has no one else come across this before?
Thanks,
John
John Guest
-
Dmitry Kulakovsky #3
Re: Create Directory
This is a relatively known .NET bug or "feature"...
Both Directory.CreateDirectory(path) and
DirectoryInfo.CreateSubdirectory(path) require user to have Read access to
the drive's root directory (i.e. <Drive>:\).
Many ASP.NET hosting providers (especially those running Windows 2003
Server) will not allow user running ASP.NET worker process read access to
the root folder, so CreateDirectory will always fail. You can not blame
hosting providers - they do right thing, securing shared environment from
users with malicious intents.
The only workaround I have found is to replace call to
Directory.CreateDirectory() with call to unmanaged code, like msvcrt's
_mkdir(char*):
[DllImport("msvcrt.dll", SetLastError=true)]
static extern int _mkdir(string path);
....
//replace call to Directory.CreateDirectory with:
_mkdir(newDirectory);
....
This will work only if your code is granted "Allow Calls to Unmanaged Code"
permission but most hosting environments allow that.
You can find more details in my recent Blog entry at
[url]http://hatka.net/wlogdev/archive/2004/08/29/178.aspx[/url]
Dmitry Kulakovsky
"John" <nospam@please.com> wrote in message
news:opr6uojhcr22ma4c@cl213.castletown.pdms.com...> Hello,
>
> I am having a permissions problem when creating a directory. The relevant
> bits of my code look like this:
>
> // impersonate current user:
> WindowsIdentity ident = (WindowsIdentity)
> HttpContext.Current.User.Identity;
> _context = ident.Impersonate();
> _name = ident.Name;
> _isauth = ident.IsAuthenticated;
> _authtype = ident.AuthenticationType;
>
> // create the directory
> // I've also tried using DirectoryInfo.Create()
> Directory.CreateDirectory(directoryName);
>
> // restore current (aspnet) identity:
> _context.Undo();
>
> If "directoryname" is "e:\inetpub\wwwroot\unittests\createdirectory\ New" I
> am getting the error Could not find a part of the path "e:\".
>
> If I grant this user access to the root of my "e" drive then it works
> fine. However, doing this is a security risk (and also, to me, seems
> completely unnecessary).
>
> Does anyone know why this happens and if there is a sensible way round
> it? Is this a .net bug?
>
> Any help would be very much appreciated as I am completely stumped!
>
> Thanks,
>
> John
Dmitry Kulakovsky Guest



Reply With Quote

