By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,663 Members | 762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,663 IT Pros & Developers. It's quick & easy.

UnauthorizedAccessException when creating virtual dir from asp.net

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <ha*******@yahoo.com> wrote in message
news:40**************************@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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.