Results 1 to 2 of 2

Thread: Create Wesite in IIS using C#(ASP.net)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    19

    Create Wesite in IIS using C#(ASP.net)

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.DirectoryServices;
    
    
    namespace IISMgrAddin
    {
        /// <summary>
        /// Summary description for IISManager.
        /// </summary>
        public class New_Web
        {
            public New_Web()
            {
    
            }
            public string CreateVDir(string WebSite, string VDirName, string Path, bool RootDir, bool chkRead, bool chkWrite, bool chkExecute, bool chkScript, bool chkAuth, int webSiteNum, string serverName)
            {
                string sRet = String.Empty;
                System.DirectoryServices.DirectoryEntry IISSchema;
                System.DirectoryServices.DirectoryEntry IISAdmin;
                System.DirectoryServices.DirectoryEntry VDir;
                bool IISUnderNT;
    
                //
                // Determine version of IIS
                //
                IISSchema = new System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/Schema/AppIsolated");
                if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN")
                    IISUnderNT = true;
                else
                    IISUnderNT = false;
                IISSchema.Dispose();
    
                //
                // Get the admin object
                //
                IISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/W3SVC/" + webSiteNum + "/Root");
    
                //
                // If we're not creating a root directory
                //
                if (!RootDir)
                {
                    //
                    // If the virtual directory already exists then delete it
                    //
    
                    foreach (System.DirectoryServices.DirectoryEntry v in IISAdmin.Children)
                    {
                        if (v.Name == VDirName)
                        {
                            // Delete the specified virtual directory if it already exists
                            try
                            {
                                IISAdmin.Invoke("Delete", new string[] { v.SchemaClassName, VDirName });
                                IISAdmin.CommitChanges();
                            }
                            catch (Exception ex)
                            {
                                sRet += ex.Message;
                            }
                        }
                    }
                }
    
                //
                // Create the virtual directory
                //
                if (!RootDir)
                {
                    VDir = IISAdmin.Children.Add(VDirName, "IIsWebVirtualDir");
                }
                else
                {
                    VDir = IISAdmin;
                }
    
                //
                // Setup the VDir
                //
                VDir.Properties["AccessRead"][0]=chkRead;
                VDir.Properties["AccessExecute"][0] = chkExecute;
                VDir.Properties["AccessWrite"][0] = chkWrite;
                VDir.Properties["AccessScript"][0] = chkScript;
                VDir.Properties["AuthNTLM"][0] = chkAuth;
                VDir.Properties["EnableDefaultDoc"][0] = "true";
                VDir.Properties["EnableDirBrowsing"][0] = false;
                VDir.Properties["DefaultDoc"][0] = true;
                VDir.Properties["Path"][0] = Path;
                VDir.Properties["DefaultDoc"] [0]= "index.aspx";
    
    
                
    
                //
                // NT doesn't support this property
                //
                if (!IISUnderNT)
                {
                    VDir.Properties["AspEnableParentPaths"][0] = true;
                }
    
                //
                // Set the changes  
                //
                VDir.CommitChanges();
    
                //
                // Make it a web application
                //
                if (IISUnderNT)
                {
                    VDir.Invoke("AppCreate", false);
                }
                else
                {
                    VDir.Invoke("AppCreate", 1);
                }
    
                sRet += "VRoot " + VDirName + " created!";
                return sRet;
            }
    
    
    
            #region Properties
            public string ServerName
            {
                get
                {
                    return _serverName;
                }
                set
                {
                    _serverName = value;
                }
            }
            #endregion
    
            public static string VirDirSchemaName = "IIsWebVirtualDir";
    
            #region Private Members
            private string _serverName;
    
            #endregion
        }
    
    
    }
    ]



    This class is working fine for Virtual diretory under default root. I want to set the properties such as Port, Ipaddress and Host Header . how hould i do that.

    Soemebody pls help me in this.


    Thanks in Advance

    Manu

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Create Wesite in IIS using C#(ASP.net)

    Please do not create duplicate threads

    Other thread:
    http://vbforums.com/showthread.php?t=467593
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width