UnauthorizedAccessException when creating virtual dir from asp.net

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default UnauthorizedAccessException when creating virtual dir from asp.net

    In c# we have a function that creates a virtual directory in IIS 6.0
    using DirectoryServices API. The code looks like this:

    // log in to IIS
    DirectoryEntry rootDir = new
    DirectoryEntry("IIS://localhost/W3SVC/1/Root",ADMIN_USR,ADMIN_PSWD,AuthenticationTypes.Sec ure);
    // create a child virtual directory
    DirectoryEntry virtualDir = rootDir.Children.Add(name,
    rootDir.SchemaClassName);
    // set the virtual directory's physical path
    virtualDir.Properties["Path"][0] = path;

    // the following line throws an UnauthorizedAccessException if called
    from a .aspx page
    // but not from a windows desktop application
    virtualDir.CommitChanges();

    Logged in as Administrator when I run this code within a windows
    application there is no problem. When I run this code called by a
    ASP.NET web application I get a "System.UnauthorizedAccessException:
    Access is denied." exception.

    The web site where the .aspx page that calls this code is set up with
    Integrated Windows Authentication or Basic Authentication and a
    user/password dialog appears the administrator account is used. In the
    web.config for the site these are the settings:

    <authentication mode="Windows" />
    <identity impersonate="true" />

    Within the above mentioned code there are entries in a log that show
    the process identity of:

    WindowsIdentity.GetCurrent().Name;
    Thread.CurrentPrincipal.Identity.Name;

    and both give the same result: DOMAIN\Administrator. Is spite of this
    we still get the UnauthorizedAccessException.

    What settings have to be changed to get this to work. Any ideas?

    Thanks in advance.
    Hal 9000 Guest

  2. Similar Questions and Discussions

    1. Creating Virtual Directories
      I'm building an application that will host many subdomains under one domain. Each subdomain will be created on the fly by a user for demo purposes....
    2. System.UnauthorizedAccessException: Access to the path error on virtual dir pointing to a network share only!
      Win 2003 DC - IIS 6.0 I received the following error when trying to run an ASP.NET app resides in a network share (on a 2003 member server). All...
    3. Creating Virtual FTP Folder in ASP.NET
      I've been running into problems when trying to create a Virtual FTP folder in ASP.Net. I've tried it a few ways but none of them has worked so far....
    4. Running XML Web Service from IIS Virtual Directory without creating application
      How do you run an XML Web Service from within an IIS Virtual Directory without creating an application. According to Microsoft you can do this,...
    5. UnauthorizedAccessException
      ASP.NET application set up as follows: machine.config set to run as "SYSTEM" web.config has impersonate="true", authentication mode="None" IIS...
  3. #2

    Default Re: UnauthorizedAccessException when creating virtual dir from asp.net

    i think its considering your default ASPNet user identity. just to test, try
    giving the required permissions to your default ASPNet user account
    only for test purposes, you can change machine.config->processModel->
    userName to SYSTEM account and test it.

    but remove this after the test. i think you need to give the required
    permissions to aspnet user (put him under power users group).
    Av.

    "Hal 9000" <hal9000cr@yahoo.com> wrote in message
    news:40a34dac.0405031330.4ca835a2@posting.google.c om...
    > In c# we have a function that creates a virtual directory in IIS 6.0
    > using DirectoryServices API. The code looks like this:
    >
    > // log in to IIS
    > DirectoryEntry rootDir = new
    > DirectoryEntry("IIS://localhost/W3SVC/1/Root",ADMIN_USR,ADMIN_PSWD,AuthenticationTypes.Sec ure);
    > // create a child virtual directory
    > DirectoryEntry virtualDir = rootDir.Children.Add(name,
    > rootDir.SchemaClassName);
    > // set the virtual directory's physical path
    > virtualDir.Properties["Path"][0] = path;
    >
    > // the following line throws an UnauthorizedAccessException if called
    > from a .aspx page
    > // but not from a windows desktop application
    > virtualDir.CommitChanges();
    >
    > Logged in as Administrator when I run this code within a windows
    > application there is no problem. When I run this code called by a
    > ASP.NET web application I get a "System.UnauthorizedAccessException:
    > Access is denied." exception.
    >
    > The web site where the .aspx page that calls this code is set up with
    > Integrated Windows Authentication or Basic Authentication and a
    > user/password dialog appears the administrator account is used. In the
    > web.config for the site these are the settings:
    >
    > <authentication mode="Windows" />
    > <identity impersonate="true" />
    >
    > Within the above mentioned code there are entries in a log that show
    > the process identity of:
    >
    > WindowsIdentity.GetCurrent().Name;
    > Thread.CurrentPrincipal.Identity.Name;
    >
    > and both give the same result: DOMAIN\Administrator. Is spite of this
    > we still get the UnauthorizedAccessException.
    >
    > What settings have to be changed to get this to work. Any ideas?
    >
    > Thanks in advance.

    avnrao Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139