473,499 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a new site on IIS using c# and ADSI

Hiya,

I'm trying to create a new site on IIS 6.0 using ADSI and C# using the
following code:

DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName +
"/w3svc", Username, Password, AuthenticationTypes.Secure);
DirectoryEntries sites = W3SVC.Children;
DirectoryEntry newSite = sites.Add("1234","IIsWebServer"); //create
a new site
newSite.CommitChanges();

The user definitely has full admin priviledges, but I'm receiving the
following error:

System.UnauthorizedAccessException: Access is denied.
at System.DirectoryServices.Interop.IAds.SetInfo()
at System.DirectoryServices.DirectoryEntry.CommitChan ges()
at UIAdmin.ConfigIIS.CreateNewWebSite(String SiteName) in
c:\inetpub\wwwroot\uiadmin\classes\configiis.cs:li ne 69

Other ADSI code work fine i.e.:

DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName +
"/w3svc", Username, Password, AuthenticationTypes.Secure);

foreach (DirectoryEntry Site in W3SVC.Children)
{
if (Site.SchemaClassName == WebServerSchema)
strSiteList += Site.Name + " - " +
Site.Properties["ServerComment"].Value.ToString() + "<br>";
}

Any ideas?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 5961
I am not sure why your credentials as you entered them are not
working, but I can give you some insight into your problem.

Calling DirectoryEntries.Add() causes the DirectoryEntry.Bind function
to be called, and the Bind function requires credentials that merely
looping through the data already sent to your box(the Children data)
does not require. Here is the call stack for DirectoryEntries.Add().

System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail) at
System.DirectoryServices.DirectoryEntry.Bind() at
System.DirectoryServices.DirectoryEntry.get_IsCont ainer() at
System.DirectoryServices.DirectoryEntries.CheckIsC ontainer() at
System.DirectoryServices.DirectoryEntries.Add(Stri ng name, String
schemaClassName)

- Jessica

Corne Grotius <co***@uiplay.com> wrote in message news:<OZ**************@TK2MSFTNGP09.phx.gbl>...
Hiya,

I'm trying to create a new site on IIS 6.0 using ADSI and C# using the
following code:

DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName +
"/w3svc", Username, Password, AuthenticationTypes.Secure);
DirectoryEntries sites = W3SVC.Children;
DirectoryEntry newSite = sites.Add("1234","IIsWebServer"); //create
a new site
newSite.CommitChanges();

The user definitely has full admin priviledges, but I'm receiving the
following error:

System.UnauthorizedAccessException: Access is denied.
at System.DirectoryServices.Interop.IAds.SetInfo()
at System.DirectoryServices.DirectoryEntry.CommitChan ges()
at UIAdmin.ConfigIIS.CreateNewWebSite(String SiteName) in
c:\inetpub\wwwroot\uiadmin\classes\configiis.cs:li ne 69

Other ADSI code work fine i.e.:

DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName +
"/w3svc", Username, Password, AuthenticationTypes.Secure);

foreach (DirectoryEntry Site in W3SVC.Children)
{
if (Site.SchemaClassName == WebServerSchema)
strSiteList += Site.Name + " - " +
Site.Properties["ServerComment"].Value.ToString() + "<br>";
}

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

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7362
by: Akhlaq Khan | last post by:
we are developing an intranet application (web based) which needs to detect the logged in user ID of the user hitting the website. the intranet is huge and based on win2k active directory (around...
3
1957
by: Jon Gross | last post by:
We have a project that will require the almost realtime (every 5 minutes) creation of user accounts and a FTP site for each of them. I would like to write a VB.Net application to do this. This...
0
1139
by: Ty R. Mote | last post by:
Is there a way (using ADSI or WMI) to create a share remotely (on a server for instance) and turn off caching (for offline folders)? We have been able to successfully use ADSI and WMI (WMI being...
1
1941
by: B. Zuidgeest | last post by:
I use C# to connect a database with student information directly to the Active Directory (2003). This means that as the student is enlisted an account and mailbox is created in the active...
6
2611
by: Jeremy S. | last post by:
Sorry if this is too far OT - I posted this in the IIS group and got no response - so here goes: What would be a good or recommended way to make a Web site in IIS6 inaccessible to users on the...
2
1154
by: Robert E. Flaherty | last post by:
Is it possible to create and maintain IIS virtual directories using .NET, either with an ASP.NET app or a C# windows app?
6
14831
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
5
3481
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the...
8
3104
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
7009
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
7223
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
6899
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
7390
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
5475
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
4919
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
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.