Directory.CreateDirectory always fails.

Discussion in 'ASP .Net Security' started by Wayne Brantley, Jul 11, 2005.

  1. 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
    Wayne Brantley, Jul 11, 2005
    #1
    1. Advertising

  2. 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


    "Wayne Brantley" <> wrote in message
    news:...
    > 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
    >
    >
    >
    Robert Hurlbut [MVP], Jul 11, 2005
    #2
    1. Advertising

  3. 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


    "Wayne Brantley" <> wrote in message
    news:...
    > 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
    >
    >
    >
    Robert Hurlbut [MVP], Jul 11, 2005
    #3
  4. 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?

    "Robert Hurlbut [MVP]" <> wrote in message
    news:%...
    > 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
    >
    >
    > "Wayne Brantley" <> wrote in message
    > news:...
    >> 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
    >>
    >>
    >>

    >
    >
    Wayne Brantley, Jul 14, 2005
    #4
  5. Wayne Brantley

    [MSFT] Guest

    [MSFT], Jul 14, 2005
    #5
  6. 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?



    "[MSFT]" <> wrote in message
    news:...
    >I agree with Robert that it may be a CAS issue. You may try to strong-name
    > the ASP.NET application and set fully trust for the assembly, will this
    > fix
    > the problem? For more info on CAS:
    >
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    > l/cpconcodeaccesssecurity.asp
    >
    > Luke
    >
    >
    Wayne Brantley, Aug 2, 2005
    #6
  7. Wayne Brantley

    [MSFT] Guest

    Hello Wayne,

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

    Luke
    [MSFT], Aug 2, 2005
    #7
  8. 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

    "[MSFT]" <> wrote in message
    news:...
    > Hello Wayne,
    >
    > Have you tried to strong-name your web service and set it full trusted on
    > the server?
    >
    > Luke
    >
    Wayne Brantley, Aug 2, 2005
    #8
  9. Wayne Brantley

    [MSFT] Guest

    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
    [MSFT], Aug 3, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GM
    Replies:
    2
    Views:
    2,210
  2. Eran Kampf
    Replies:
    7
    Views:
    6,237
    Eran Kampf
    Oct 13, 2004
  3. Andrew R. Jones
    Replies:
    2
    Views:
    3,539
    Andrew R. Jones
    Jan 5, 2006
  4. Chad
    Replies:
    6
    Views:
    2,792
  5. Matt MacDonald
    Replies:
    0
    Views:
    390
    Matt MacDonald
    Jan 30, 2008
Loading...

Share This Page