473,660 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating website via DirectoryServic es in C# but will not serve aspxpages (htm ok)

I've seen a similar post about this problem but still cannot find an
automated solution. Below is the code I'm using to create a website
(for IIS 6.0) via C#. once the site is created, it will not serve aspx
pages. If I:

1. go to IIS Manager
2. view the properties for the site in question
3. go to the [Home Directory] tab
4. click [Remove] next to the Application Name textbox in the
Application Settings area.
5. click on [Add] to add the application back in.

The site works as expected.

Can anyone help me out? Feel free to email me at

mustafashabib [at] sbcglobal [dot] net

thanks.
Nov 26 '07 #1
1 1391
On Nov 26, 5:44 pm, MMAS <mustafasha...@ gmail.comwrote:
I've seen a similar post about this problem but still cannot find an
automated solution. Below is the code I'm using to create a website
(for IIS 6.0) via C#. once the site is created, it will not serve aspx
pages. If I:

1. go to IIS Manager
2. view the properties for the site in question
3. go to the [Home Directory] tab
4. click [Remove] next to the Application Name textbox in the
Application Settings area.
5. click on [Add] to add the application back in.

The site works as expected.

Can anyone help me out? Feel free to email me at

mustafashabib [at] sbcglobal [dot] net

thanks.
sorry, the code is as follows:
public static int CreateNewWebsit e(string website_name, int port,
string path_to_website _root)
{
try
{
DirectoryEntry root = new DirectoryEntry( "IIS://
localhost/W3SVC");
// Find unused ID value for new web site

bool found_valid_sit e_id = false;
int random_site_id = 1;
do
{
bool regenerate_site _id = false;
System.Random random_generato r = new Random();
random_site_id = random_generato r.Next();

foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassN ame == "IIsWebServ er")
{

int current_site_id =
Convert.ToInt32 (e.Name);
if (current_site_i d == random_site_id)
{
regenerate_site _id = true;
break;
}
}
}

found_valid_sit e_id = !regenerate_sit e_id;
} while (!found_valid_s ite_id);

// Create web site

DirectoryEntry site =
(DirectoryEntry )root.Invoke("C reate", "IIsWebServ er", random_site_id) ;

site.Invoke("Pu t", "ServerComment" , website_name +
String.Format(" - ({0})", port));

site.Invoke("Pu t", "KeyType", "IIsWebServer") ;

site.Invoke("Pu t", "ServerBindings ", ":" +
port.ToString() + ":");

site.Invoke("Pu t", "ServerStat e", 2);

//site.Invoke("Pu t", "FrontPageW eb", 1);

//site.Invoke("Pu t", "DefaultDoc ",
"Default.aspx,D efault.html,Def ault.html,Index .aspx,Index.htm ,Index.html");

// site.Invoke("Pu t", "SecureBindings ", ":443:");

site.Invoke("Pu t", "ServerAutoStar t", 1);

site.Invoke("Pu t", "ServerSize ", 1);

site.Invoke("Se tInfo");

//create app website directory
site.Authentica tionType =
AuthenticationT ypes.Anonymous;
// site.Username = username;
// site.Password = password;

// DirectoryEntry website_directo ry =
site.Children.A dd("Root", "IIsWebDirector y");
// website_directo ry.Properties["Location"][0] = "/
LM/W3SVC/" + random_site_id. ToString() + "/root/aspnet_client";
// website_directo ry.Properties["AccessFlag s"][0] =
"AccessRead ";
// website_directo ry.Properties["DirBrowseFlags "]
[0] = "0";
// website_directo ry.CommitChange s();
// Create application virtual directory
DirectoryEntry virtual_directo ry =
site.Children.A dd("Root", "IISWebVirtualD ir");

virtual_directo ry.Properties["AppIsolate d"][0] =
2;

if (path_to_websit e_root.EndsWith ("\\"))
{
path_to_website _root =
path_to_website _root.Substring (0, path_to_website _root.Length - 1);
}

virtual_directo ry.Properties["Path"][0] =
path_to_website _root;
virtual_directo ry.Invoke("AppC reate", true);

virtual_directo ry.Properties["EnableDirBrows ing"]
[0] = false ;
virtual_directo ry.Properties["AccessExec ute"][0] =
true;
virtual_directo ry.Properties["AccessRead "][0] =
true;
virtual_directo ry.Properties["AccessWrit e"][0] =
false;
virtual_directo ry.Properties["AuthAnonym ous"][0] =
true;
virtual_directo ry.Properties["AuthBasic"][0] =
false;
virtual_directo ry.Properties["AuthNTLM"][0] =
true;
virtual_directo ry.Properties["AppFriendlyNam e"][0]
= website_name;
virtual_directo ry.Properties["AppRoot"][0] = "LM/
W3SVC/" + random_site_id. ToString() +"/Root";
virtual_directo ry.CommitChange s();

site.CommitChan ges();
//
RunApplication( Environment.Exp andEnvironmentV ariables(@"%Sys temRoot%
\Microsoft.NET\ Framework\v2.0. 50727\aspnet_re giis.exe"), "-i");// + "/
W3SVC/" + random_site_id. ToString() + "/Root");
virtual_directo ry.Close();
site.Close();

RunApplication( Environment.Exp andEnvironmentV ariables(@"%Sys temRoot%
\Microsoft.NET\ Framework\v2.0. 50727\aspnet_re giis.exe"), "-s " + "/
W3SVC/" + random_site_id. ToString() +"/Root");

RunApplication( Environment.Exp andEnvironmentV ariables(@"%Sys temRoot%
\Microsoft.NET\ Framework\v2.0. 50727\aspnet_re giis.exe"), "-c");
return random_site_id;
}
catch (Exception ex)
{
throw new Exception("An error occurred trying to
create a website.", ex);
}
}

private static string RunApplication( string location,
string arguments)
{
System.Diagnost ics.ProcessStar tInfo psi = new
System.Diagnost ics.ProcessStar tInfo(location) ;
psi.Arguments = arguments;
psi.RedirectSta ndardOutput = true;
psi.WindowStyle =
System.Diagnost ics.ProcessWind owStyle.Hidden;
psi.UseShellExe cute = false;
System.Diagnost ics.Process listFiles;
listFiles = System.Diagnost ics.Process.Sta rt(psi);
System.IO.Strea mReader myOutput =
listFiles.Stand ardOutput;
listFiles.WaitF orExit(2000);
string output = "";
if (listFiles.HasE xited)
{
output = myOutput.ReadTo End();

}

return output;
}
Nov 26 '07 #2

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

Similar topics

12
9607
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I instanciate SearchResultCollection Class. more clearly, a SearchResult object is created, at the inside of FindAll() method, then how can I put this object into the SearchResultCollection object. there is any method releated to input operation.
1
5971
by: Corne Grotius | last post by:
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
1
4857
by: Stephanie Stowe | last post by:
Hi. I am trying to read information out of the IIS metabase (v5.1). Observe the following code: using System; using System.DirectoryServices; using System.Reflection; namespace ADSI1 { class ConfigIIS
15
6743
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use javascript or vbscript it works. I will appreciate any help. I do the following (C#):
7
2388
by: Jaydeep | last post by:
Hi, Anybody knows how to create virtual directory programmatically under root directory ofcourse from code-behind. I am developing web-based application where I need to create a folder and making this folder as virtual directory in IIS. I know in ASP how to do it. Set objIIS = GetObject("IIS://localhost/W3SVC/1/Root") objIIS.Create("IISWebVirtualDir", strVirtualDirectoryName)
5
3491
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 case. One handle remains open. Debugging shows that it's actually the IIS cache and not ASP.NET that owns this handle. During IIS shutdown, the handle is closed with the following stack trace: ChildEBP RetAddr 0006fbe4 5a403e05...
1
4927
by: sudhapadmas | last post by:
Hello netters, I was trying to create a virtual directory in IIS using the following code: System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();
10
4908
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're called, an example of what I have in mind is index.php?page=). However, I can not figure out how to do this. I will eventually want to use SEF urls, but for now I'll be content just to have the dynamic urls. If anyone can tell me how to do this, I'd...
1
1297
by: Mick Walker | last post by:
Hi all, I am wondering is it possible to create a physical Directory such as "C:\Test" using the DirectoryServices namespace. If so, does anyone have any resources on how to do it? I should also mention, I am required to create the physical directory on any machine within the current AD domain. Kind Regards
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.