473,467 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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.
Nov 18 '05 #1
1 1835
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: GM | last post by:
Any help is greatly appreciated! I'm up against a meeting deadline. Directory.CreateDirectory Method throws UnauthorizedAccessException Here is the path: ...
12
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files...
5
by: Kristoffer Persson | last post by:
Hi all! I'm trying to use a named EventWaitHandle to signal events between processes that run on the same computer. One of them is a service running as SYSTEM and the other one is a normal user....
3
by: BLUE | last post by:
I've created a folder named TestDir in my wwwroot and I've created the associated virtual application from IIS management snap-in. I've given full control to TestDir to: IUSR, ASPNET, Network...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.