Directory.CreateDirectory always fails.

W

Wayne Brantley

Using a webservice in asp.net, I make a call to
Directory.CreateDirectory(@"c:\test") and this works fine.
I can create any directory anywhere on my local machine.

Now, I have an iomega NAS on the network. (There is not a domain). This
drive does NOT use permissions and essentially everyone who can access it
can do anything on it. It maps to my computer as drive 'n:'.

If I use that same webservice and call Directory.CreateDirectory(@"n:\test")
it fails with: Could not find a part of the path "n:\"

I have read every article on this twice and tried everything - nothing
works:

1) I tried using _mkdir, just for kicks -
http://hatka.net/wlogdev/archive/2004/08/29/178.aspx
2) <identity impersonate="true"
3) Impersonation in code -
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306158#4 (Checking
System.Security.Principal.WindowsIdentidy.GetCurrent().Name before and after
impersonation shows the context changed, but the CreateDirectory fails
anyway.
4) Changing the account aspnet_wp runs under - changed it to system and to
my poweruser account I am using, neither helped.


I wrote a small regular .net application that makes a call to
Directory.CreateDirectory(@"n:\test") and it succeeds, so I know the NAS is
working correctly and it has to be a permissions issue of some kind, but
cannot figure out what.

(Running under XP SP2)


Wayne
 
R

Robert Hurlbut [MVP]

I am not certain (as I haven't tried this yet), but it could be a CAS (Code
Access Security) issue as you are running an intranet site to update what
may look like a network share. What is the exact exception (wording) you are
getting?

Robert Hurlbut
Security Developer MVP
 
R

Robert Hurlbut [MVP]

My apologies -- I see the error you mentioned in your question.

I got the same error recently for an application doing something similar.
Even though you may have given everyone permission to the folder/drive, have
you set the permissions on the share settings as well? I believe by default,
the permissions are set to "Read Only".

Robert Hurlbut
Security Developer MVP
 
W

Wayne Brantley

Keep in mind this is a NAS that essentially has one built in share and there
are NO permissions that can even be set - the device does not enforce
permissions.

I also tried it to shares that are on a domain, using a domain admin
account - with the same error. Any ideas?
 
W

Wayne Brantley

I have now created a class that is called from a console application that
calls Directory.CreateDirectory.
When called from the console all works fine.
I then called it from a service. I had the service logon as the
administrator and it fails with the same error.

Any other ideas?
 
M

[MSFT]

Hello Wayne,

Have you tried to strong-name your web service and set it full trusted on
the server?

Luke
 
W

Wayne Brantley

I finally got it working. It must be some sort of OS (Windows XP SP2) or
..net bug.

Create directory works on a path like
"\\server\share\folder\folder\folder\folder"

However, if you connect a network drive to "\\server\share", say drive s:
and then try to use CreateDirectory on a path of
"s:\folder\folder\folder\folder" it always gives the errors described.

Can you check into this and see if this issue has been reported?

Wayne
 
M

[MSFT]

It looks still a code access security error, you may try open assembly.cs
in your project and add following code:

using System.Security;
using System.Security.Permissions;

[assembly:FileIOPermission(SecurityAction.RequestMinimum,Unrestricted=true)]
// Request complete File IO functionality
[assembly:RegistryPermission(SecurityAction.RequestMinimum, All="*")]
//Request complet access to the registery key
[assembly:ZoneIdentityPermission(SecurityAction.RequestMinimum,Zone=Security
Zone.NoZone)] // Request unrestricted zone

These will help your application to require proper permission.

Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top