PC Review


Reply
Thread Tools Rate Thread

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

 
 
MMAS
Guest
Posts: n/a
 
      26th Nov 2007
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.
 
Reply With Quote
 
 
 
 
MMAS
Guest
Posts: n/a
 
      26th Nov 2007
On Nov 26, 5:44 pm, MMAS <mustafasha...@gmail.com> wrote:
> 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 CreateNewWebsite(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_site_id = false;
int random_site_id = 1;
do
{
bool regenerate_site_id = false;
System.Random random_generator = new Random();
random_site_id = random_generator.Next();

foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IIsWebServer")
{

int current_site_id =
Convert.ToInt32(e.Name);
if (current_site_id == random_site_id)
{
regenerate_site_id = true;
break;
}
}
}

found_valid_site_id = !regenerate_site_id;
} while (!found_valid_site_id);

// Create web site

DirectoryEntry site =
(DirectoryEntry)root.Invoke("Create", "IIsWebServer", random_site_id);

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

site.Invoke("Put", "KeyType", "IIsWebServer");

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

site.Invoke("Put", "ServerState", 2);

//site.Invoke("Put", "FrontPageWeb", 1);

//site.Invoke("Put", "DefaultDoc",
"Default.aspx,Default.html,Default.html,Index.aspx,Index.htm,Index.html");

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

site.Invoke("Put", "ServerAutoStart", 1);

site.Invoke("Put", "ServerSize", 1);

site.Invoke("SetInfo");

//create app website directory
site.AuthenticationType =
AuthenticationTypes.Anonymous;
// site.Username = username;
// site.Password = password;

// DirectoryEntry website_directory =
site.Children.Add("Root", "IIsWebDirectory");
// website_directory.Properties["Location"][0] = "/
LM/W3SVC/" + random_site_id.ToString() + "/root/aspnet_client";
// website_directory.Properties["AccessFlags"][0] =
"AccessRead";
// website_directory.Properties["DirBrowseFlags"]
[0] = "0";
// website_directory.CommitChanges();


// Create application virtual directory
DirectoryEntry virtual_directory =
site.Children.Add("Root", "IISWebVirtualDir");

virtual_directory.Properties["AppIsolated"][0] =
2;

if (path_to_website_root.EndsWith("\\"))
{
path_to_website_root =
path_to_website_root.Substring(0, path_to_website_root.Length - 1);
}



virtual_directory.Properties["Path"][0] =
path_to_website_root;
virtual_directory.Invoke("AppCreate", true);

virtual_directory.Properties["EnableDirBrowsing"]
[0] = false ;
virtual_directory.Properties["AccessExecute"][0] =
true;
virtual_directory.Properties["AccessRead"][0] =
true;
virtual_directory.Properties["AccessWrite"][0] =
false;
virtual_directory.Properties["AuthAnonymous"][0] =
true;
virtual_directory.Properties["AuthBasic"][0] =
false;
virtual_directory.Properties["AuthNTLM"][0] =
true;
virtual_directory.Properties["AppFriendlyName"][0]
= website_name;
virtual_directory.Properties["AppRoot"][0] = "LM/
W3SVC/" + random_site_id.ToString() +"/Root";


virtual_directory.CommitChanges();

site.CommitChanges();
//
RunApplication(Environment.ExpandEnvironmentVariables(@"%SystemRoot%
\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe"), "-i");// + "/
W3SVC/" + random_site_id.ToString() + "/Root");
virtual_directory.Close();
site.Close();

RunApplication(Environment.ExpandEnvironmentVariables(@"%SystemRoot%
\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe"), "-s " + "/
W3SVC/" + random_site_id.ToString() +"/Root");

RunApplication(Environment.ExpandEnvironmentVariables(@"%SystemRoot%
\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.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.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo(location);
psi.Arguments = arguments;
psi.RedirectStandardOutput = true;
psi.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput =
listFiles.StandardOutput;
listFiles.WaitForExit(2000);
string output = "";
if (listFiles.HasExited)
{
output = myOutput.ReadToEnd();

}

return output;
}
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Physical Directory Using DirectoryServices Mick Walker Microsoft ASP .NET 3 26th Oct 2007 09:55 AM
Word Document triggers user name and password for website on serve =?Utf-8?B?R291ZGE=?= Microsoft Frontpage 1 25th Sep 2006 02:48 AM
DirectoryServices.DirectoryEntry - Creating virtual directories in =?Utf-8?B?cGF1bA==?= Microsoft Dot NET Framework 3 9th Aug 2005 12:51 AM
ms-access serve both desktop and the website =?Utf-8?B?eXV5dQ==?= Microsoft Access Getting Started 3 29th Nov 2004 05:31 AM
creating a list serve blamb Microsoft Windows 2000 0 22nd Jul 2003 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:52 PM.