|
//////////////////////////////////////////////////////////////////////////
// DNN Module Packager 1.0
// Copyright (C) 2004-2005 Matt Long
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// You can contact the author at: matt.long@matthew-long.com
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.DirectoryServices;
using System.Collections;
namespace SkyeRoad.DNNTools
{
/// <summary>
/// Summary description for VirtualDirectoryUtility.
/// </summary>
public class VirtualDirectoryUtility
{
public VirtualDirectoryUtility()
{
}
public Hashtable GetSitePaths()
{
Hashtable tmp = new Hashtable();
DirectoryEntry root = new DirectoryEntry("IIS://localhost/w3svc/1/root");
foreach( DirectoryEntry e in root.Children )
{
tmp[ e.Name ] = e.Path;
}
return tmp;
}
public string GetVirtualDirLocalPath( string directoryEntry )
{
DirectoryEntry virtualPath = new DirectoryEntry( directoryEntry );
return virtualPath.Properties["Path"].Value.ToString();
}
public int CreateWebSite(string webSiteName, string pathToRoot)
{
return CreateWebSite(webSiteName, pathToRoot, false);
}
public int CreateWebSite(string webSiteName, string pathToRoot, bool createDir)
{
string entryRoot = "IIS://localhost/W3SVC";
DirectoryEntry root = new DirectoryEntry(entryRoot);
// Find unused ID value for new web site
int siteID = 1;
foreach(DirectoryEntry e in root.Children)
{
if(e.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(e.Name);
if(ID >= siteID)
{
siteID = ID+1;
}
}
}
// Create web site
DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
site.Invoke("Put", "ServerComment", webSiteName);
site.Invoke("Put", "KeyType", "IIsWebServer");
site.Invoke("Put", "ServerBindings", ":80:");
site.Invoke("Put", "ServerState", 2);
site.Invoke("Put", "FrontPageWeb", 1);
site.Invoke("Put", "DefaultDoc", "Default.aspx");
site.Invoke("Put", "SecureBindings", ":443:");
site.Invoke("Put", "ServerAutoStart", 1);
site.Invoke("Put", "ServerSize", 1);
site.Invoke("SetInfo");
// Create application virtual directory
DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");
siteVDir.Properties["AppIsolated"][0] = 2;
siteVDir.Properties["Path"][0] = pathToRoot;
siteVDir.Properties["AccessFlags"][0] = 513;
siteVDir.Properties["FrontPageWeb"][0] = 1;
siteVDir.Properties["AppRoot"][0] = "/LM/W3SVC/"+siteID+"/Root";
siteVDir.Properties["AppFriendlyName"][0] = "Root";
siteVDir.CommitChanges();
site.CommitChanges();
return siteID;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.