IIS ADSI virtual dir creation problem from web application

From: Gabriel R (rozsagabor_at_yahoo.com)
Date: 11/25/04


Date: Thu, 25 Nov 2004 01:59:47 -0800

I am trying to create a virtual directory using ADSI, with the following
C# code:

string Server = <srv>;
string ApplicationName = <app>;
DirectoryEntry root = new DirectoryEntry("IIS://" + Server +
"/W3SVC/1/Root", adminusername, adminuserpass);
// look up the virtual dir
DirectoryEntry app = null;
foreach (DirectoryEntry e in root.Children)
{
 if (e.SchemaClassName == "IISWebVirtualDir" && e.Name.ToUpper() ==
ApplicationName.ToUpper())
        {
                app = e; break;
        }
}
if (app == null)
{
        // create the virtual dir
        app = root.Children.Add(ApplicationName, "IISWebVirtualDir");
}
// create the application attached to it
app.Invoke("AppCreate", false);
// set the properties of the virtual dir
app.Properties["Path"][0] = "D:\\Web";
app.Properties["DefaultDoc"][0] = "default.aspx";
app.Properties["AppFriendlyName"][0] = ApplicationName;
app.CommitChanges();

The code works fine if I run it from a Windows Forms application,
however if it's run from a web application I get a COMException: Access
denied.
The web application runs under the credentials of the admin user (I used
<identity impersonate=true ...> in web.config).

How could I solve this problem?

Gabriel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Using Generics with System.DirectoryServices
    ... First, I never used the WinNT objects, I always used LDAP. ... I'm in the process of updating an ASP.NET v1.1 web app to v2. ... DirectoryEntry objADEntry = null; ... foreach (object objChild in (IEnumerable)objChildren) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Invoke(SetPassword) in Active Directory, Works, Then Access is
    ... ADAM) to check out what the server is advertising for its capabilities. ... internal static DirectoryEntry GetDirectoryObject(string UserName, ... // Run the invoke from a console app, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: Add New Users
    ... your ASP.NET app is set up for anonymous access. ... are a couple of ways to accomplish what you want. ... Dim grp As DirectoryEntry ...
    (microsoft.public.dotnet.framework.aspnet)
  • ADSI WinNT cant delete computer object
    ... the "DirectoryEntry" object to bind to an NT4 domain and ... accounts with this app. ... In my test nt4 domain environment, ... In my program I can bind to it and traverse its ...
    (microsoft.public.security)
  • Re: ADSI script implement in C#
    ... My customer does not like to add the reference since it's .NET application. ... I'm not quite good at ADSI, however, based on my research, the problem here ... Microsoft MSDN Online Support Lead ... DirectoryEntry de = new DirectoryEntry; ...
    (microsoft.public.dotnet.languages.csharp)