当前位置:编程学习 > C#/ASP.NET >>

VS2005打包,制作Web安装程序时,如何建立IIS站点?

原来用VS2005自带的安装部署里的"Web安装项目"制作安装盘,可是这样要另外在IIS设置"虚拟目录"的属性等,比较麻烦.
现在想用"安装项目"制作安装盘,在IIS上建立站点,请问要怎么写? --------------------编程问答-------------------- 参考 http://www.aspxboy.com/private/4339/default.aspx --------------------编程问答-------------------- http://www.aspxboy.com/private/2676/default.aspx

http://www.aspxboy.com/private/5200/default.aspx

http://www.aspxboy.com/2256/default.aspx --------------------编程问答-------------------- 谢谢 xiahouwen(武眉博<活靶子.NET>) 
不过这些好像都是对虚拟目录的操作,而不是对站点的操作
--------------------编程问答-------------------- 下面的代码如果放到单独的项目里,就可以在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;
        }
    }
}
--------------------编程问答-------------------- 前几天,看过一个帖子,也是说这事的。我找找~~JF --------------------编程问答-------------------- 找到了,
<<< 100分,100分 >>> 打包部署。操作iis建立网站(而不是虚拟目录),谢谢了 

http://community.csdn.net/Expert/topic/5728/5728241.xml?temp=.6934931

里面有孟子的讨论,很好的,JF,JF --------------------编程问答-------------------- 对网站进行操作,需要在执行安装程序之前,完成,比如通过一段批处理脚本 --------------------编程问答-------------------- 对 octverve(生命无色,命运多彩……) 
  好像没有结果,他们说的,在单独项目里可以建立IIS站点,可是放到安装项目里就不行了,也没办法看到是哪里错了

对 Jinglecat(晓风残月 >> 问题需简洁,错误要详细,需求得明确)
  在安装项目里添加一个安装类(就是上面的代码),然后在文件系统的"应用程序文件夹"下面添加"项目输出"(这个类的主输出),再在自定义操作里的"安装"添加"自定义操作",添加这个主输出
这样没错吧

先谢谢两位! --------------------编程问答-------------------- 学习中.........呵呵........... --------------------编程问答-------------------- 现在可以建了

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

请问有谁帮助一下??? --------------------编程问答-------------------- site.Invoke("Put", "DefaultDoc", "Default.aspx"); --------------------编程问答-------------------- 网站打包程序:
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   
可直接使用! --------------------编程问答-------------------- 学习了
--------------------编程问答-------------------- 学习中。................... --------------------编程问答-------------------- 学习中 --------------------编程问答-------------------- 路过,来学习下
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,