参考 http://www.aspxboy.com/private/4339/default.aspx

解决方案 »

  1.   

    http://www.aspxboy.com/private/2676/default.aspxhttp://www.aspxboy.com/private/5200/default.aspxhttp://www.aspxboy.com/2256/default.aspx
      

  2.   

    谢谢 xiahouwen(武眉博<活靶子.NET>) 
    不过这些好像都是对虚拟目录的操作,而不是对站点的操作
      

  3.   

    下面的代码如果放到单独的项目里,就可以在IIS上建立站点(把Install(...)的内容放到一个按钮事件里).
    现在放在"安装项目"的一个类里,却是怎么也不能建立站点有谁做过这一块的,帮助一下using System;
    using System.IO;
    using System.DirectoryServices;
    using System.Reflection;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration.Install;
    using System.Management;
    using System.Collections;
    using Microsoft.Win32;
    using System.Collections.Specialized;namespace SetupClassLibrary
    {
        public partial class MyInstaller : Installer
        {
            static DirectoryEntry iisDE = new DirectoryEntry("IIS://localhost/W3SVC");
            public MyInstaller()
            {
            }
            #region Install 安装
            public override void Install(IDictionary stateSaver)
            {
                base.Install(stateSaver);
                string serverComment = "MyWebSetup";
                string defaultVrootPath = this.Context.Parameters["targetdir"];
                if (defaultVrootPath.EndsWith(@"\"))
                {
                    defaultVrootPath = defaultVrootPath.Substring(0, defaultVrootPath.Length - 1);
                }
                int Port = 9998;
                CreateNewIIsWebServer(serverComment, defaultVrootPath, Port);
            }
            #endregion        
            public void CreateNewIIsWebServer(string webServerName, string path, int port)
            {
                int siteID = GetWebSiteInfo(port);
                using (DirectoryEntry site = (DirectoryEntry)iisDE.Invoke("Create", "IIsWebServer", siteID))
                {
                    site.Invoke("Put", "ServerComment", webServerName);
                    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", "index.aspx");
                    site.Invoke("Put", "SecureBindings", ":443:");
                    site.Invoke("Put", "ServerAutoStart", 1);
                    site.Invoke("Put", "ServerSize", 1);
                    site.Invoke("SetInfo");
                    using (DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir"))
                    {
                        siteVDir.Properties["AppIsolated"][0] = 2;
                        siteVDir.Properties["Path"][0] = path;
                        siteVDir.Properties["AccessFlags"][0] = 513;
                        siteVDir.Properties["FrontPageWeb"][0] = 1;
                        siteVDir.Properties["AppFriendlyName"][0] = webServerName;
                        siteVDir.Invoke("AppCreate", true);
                        siteVDir.CommitChanges();
                    }
                    site.CommitChanges();
                }
            }
            private int GetWebSiteInfo(int port)
            {
                int result = 1, i = 1;
                DirectoryEntries des = iisDE.Children;
                foreach (DirectoryEntry subDE in des)
                {
                    if (subDE.SchemaClassName == "IIsWebServer")
                    {
                        if ((i = Convert.ToInt32(subDE.Name)) >= result)
                        {
                            result = i + 1;
                        }
                        if (subDE.Properties["ServerBindings"][0].ToString() == ":" + port.ToString() + ":")
                        {
                            throw new Exception(" The port is already used");
                        }
                    }
                }
                des = null;
                return result;
            }
        }
    }
      

  4.   

    找到了,
    <<< 100分,100分 >>> 打包部署。操作iis建立网站(而不是虚拟目录),谢谢了 http://community.csdn.net/Expert/topic/5728/5728241.xml?temp=.6934931里面有孟子的讨论,很好的,JF,JF
      

  5.   

    对 octverve(生命无色,命运多彩……) 
      好像没有结果,他们说的,在单独项目里可以建立IIS站点,可是放到安装项目里就不行了,也没办法看到是哪里错了对 Jinglecat(晓风残月 >> 问题需简洁,错误要详细,需求得明确)
      在安装项目里添加一个安装类(就是上面的代码),然后在文件系统的"应用程序文件夹"下面添加"项目输出"(这个类的主输出),再在自定义操作里的"安装"添加"自定义操作",添加这个主输出
    这样没错吧先谢谢两位!
      

  6.   

    现在可以建了只是建好的站点和直接在IIS上建的不一样(但里面的设置是一样的),浏览站点的时候打开的是
    http://localhost/localstart.asp而不是http://localhost/Default.aspx
    直接浏览Default.aspx, 打开后报错:
    无法找到资源。 
    说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
    请求的 URL: /Default.aspx请问有谁帮助一下???
      

  7.   

    site.Invoke("Put", "DefaultDoc", "Default.aspx");
      

  8.   

    网站打包程序:
    http://www.cnblogs.com/cncxz/archive/2005/11/30/287602.html 
    演示应用下载:http://www.cnblogs.com/Files/cncxz/webSetupDemo.rar   
    开源代码下载::http://www.cnblogs.com/Files/cncxz/webSetupSource.rar   
    可直接使用!