示例#1
0
        public bool MIMESetting(DirectoryEntry rootEntry, Dictionary <string, string> exList)
        {
            if (rootEntry == null)
            {
                return(false);
            }
            System.DirectoryServices.PropertyValueCollection mime = rootEntry.Properties["MimeMap"];

            foreach (string e in exList.Keys)
            {
                IISOle.MimeMapClass Ex = new IISOle.MimeMapClass();
                Ex.Extension = e;
                Ex.MimeType  = exList[e];
                object v = ContianValue(Ex, mime);
                if (v != null)
                {
                    continue;
                    //mime.Remove(v);
                }
                mime.Add(Ex);
                Ex = null;
            }
            rootEntry.CommitChanges();
            return(true);
        }
示例#2
0
 /// <summary>
 /// 设置站点新增自定义mime类型,一次添加一个类型
 /// </summary>
 /// <param name="siteInfo"></param>
 /// <param name="mysiteServer"></param>
 public void addMIMEtype(newWebSiteInfo siteInfo, DirectoryEntry mysiteServer)
 {
     //需要添加新的mime类型
     if (siteInfo.newMimeType.Count > 0)
     {
         IISOle.MimeMapClass NewMime = new IISOle.MimeMapClass();
         NewMime.Extension = siteInfo.newMimeType.Keys.ToString(); NewMime.MimeType = siteInfo.newMimeType.Values.ToString();
         IISOle.MimeMapClass TwoMime = new IISOle.MimeMapClass();
         mysiteServer.Properties["MimeMap"].Add(NewMime);
         mysiteServer.CommitChanges();
     }
 }
示例#3
0
        /// <summary>
        /// 创建网站
        /// </summary>
        /// <param name="siteInfo"></param>
        public DirectoryEntry CreateNewWebSite(NewWebSiteInfo siteInfo)
        {
            DirectoryEntry newSiteEntry = GetDirEntry(siteInfo.CommentOfWebSite, siteInfo.BindString);

            if (newSiteEntry != null)
            {
                //throw new Exception("该网站名或者端口已存在" + Environment.NewLine + siteInfo.BindString);
                return(newSiteEntry);
            }
            DirectoryEntry rootEntry = GetDirectoryEntry(entPath);

            var newSiteNum = GetNewWebSiteID();

            newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");
            newSiteEntry.CommitChanges();

            newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
            newSiteEntry.Properties["ServerComment"].Value  = siteInfo.CommentOfWebSite;
            newSiteEntry.CommitChanges();
            DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");

            vdEntry.CommitChanges();
            string ChangWebPath = siteInfo.WebPath.TrimEnd('\\');

            if (!Directory.Exists(ChangWebPath))
            {
                Directory.CreateDirectory(ChangWebPath);//创建目录
            }
            vdEntry.Properties["Path"].Value = ChangWebPath;


            vdEntry.Invoke("AppCreate", true);                                    //创建应用程序

            vdEntry.Properties["AccessRead"][0]      = true;                      //设置读取权限
            vdEntry.Properties["AccessWrite"][0]     = true;
            vdEntry.Properties["AccessScript"][0]    = true;                      //执行权限
            vdEntry.Properties["AccessExecute"][0]   = false;
            vdEntry.Properties["DefaultDoc"][0]      = "Default.aspx";            //设置默认文档
            vdEntry.Properties["AppFriendlyName"][0] = siteInfo.CommentOfWebSite; //应用程序名称
            vdEntry.Properties["AuthFlags"][0]       = 1;                         //0表示不允许匿名访问,1表示就可以3为基本身份验证,7为windows继承身份验证
            vdEntry.CommitChanges();

            //操作增加MIME
            //.dwf drawing/x-dwf
            //.dwg application/autocad
            //.dxf application/dxf
            //X-Powered-By ASP.NET
            var mineDic = siteInfo.MineDic;

            foreach (var str in mineDic)
            {
                IISOle.MimeMapClass NewMime = new IISOle.MimeMapClass();
                NewMime.Extension = str.Key; NewMime.MimeType = str.Value;
                vdEntry.Properties["MimeMap"].Add(NewMime);
            }
            if (mineDic.Count() > 0)
            {
                vdEntry.CommitChanges();
                rootEntry.CommitChanges();
            }

            #region 针对IIS7
            DirectoryEntry getEntity = new DirectoryEntry("IIS://localhost/W3SVC/INFO");
            int            Version   = int.Parse(getEntity.Properties["MajorIISVersionNumber"].Value.ToString());
            if (Version > 6)
            {
                #region 创建应用程序池
                string AppPoolName = siteInfo.CommentOfWebSite;
                if (!IsAppPoolName(AppPoolName))
                {
                    DirectoryEntry newpool;
                    DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    newpool = appPools.Children.Add(AppPoolName, "IIsApplicationPool");

                    newpool.CommitChanges();
                }
                #endregion

                #region 修改应用程序的配置(包含托管模式及其NET运行版本)
                ServerManager sm = new ServerManager();
                sm.ApplicationPools[AppPoolName].ManagedRuntimeVersion = "v4.0";
                sm.ApplicationPools[AppPoolName].ManagedPipelineMode   = ManagedPipelineMode.Integrated; //托管模式Integrated为集成 Classic为经典
                sm.CommitChanges();
                #endregion

                vdEntry.Properties["AppPoolId"].Value = AppPoolName;
                vdEntry.CommitChanges();
            }
            #endregion


            //启动aspnet_regiis.exe程序
            string           fileName  = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe";
            ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
            //处理目录路径
            string path  = vdEntry.Path.ToUpper();
            int    index = path.IndexOf("W3SVC");
            path = path.Remove(0, index);
            //启动ASPnet_iis.exe程序,刷新脚本映射
            startInfo.Arguments              = "-s " + path;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            Process process = new Process();
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
            string errors = process.StandardError.ReadToEnd();
            if (errors != string.Empty)
            {
                throw new Exception(errors);
            }
            return(newSiteEntry);
        }
示例#4
0
        /// <summary>
        /// Create an Application VDir for this directory and set its properties to allow the execution of WCF Services
        /// </summary>
        static void CreateApplicationVDir(string applicationName)
        {
            DirectoryEntry site      = new DirectoryEntry(FindSharepointRootPath()); // BUGBUG: Do we want to hardcode this installer to just SharePoint?
            string         className = site.SchemaClassName.ToString();

            DirectoryEntries vdirs = site.Children;

            #region Delete old Application if it exists
            foreach (DirectoryEntry de in vdirs)
            {
                if (de.Name == applicationName)
                {
                    Console.WriteLine(Strings.DeletingExistingApplication, de.Name);
                    de.DeleteTree(); // Out with the old, in with the new!
                }
            }
            #endregion

            #region Add the new Application
            Console.WriteLine(Strings.AddingNewApplication, applicationName);

            DirectoryEntry vdir = vdirs.Add(applicationName, className);
            vdir.Properties["AppFriendlyName"][0] = applicationName;

            string currentPath = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName;
            vdir.Properties["Path"][0]         = currentPath;                       // Set this from the currently executing directory
            vdir.Properties["AccessScript"][0] = true;                              // Allow scripts
            vdir.Properties["AuthFlags"][0]    = "1";                               // Turn on Anonymous authentication
            vdir.Invoke("AppCreate3", new object[] { 0, "SLK Services", true });    // Make this an Application vdir running in process in a new AppPool named "SLK Services"

            vdir.CommitChanges();
            #endregion

            #region Fix up the ScriptMap setting that SharePoint removes which breaks WCF Services
            vdir.RefreshCache(); // Load the default properties that were inherited when the Application was committed
            foreach (PropertyValueCollection pvc in vdir.Properties)
            {
                if (pvc.PropertyName == "ScriptMaps") // Update the ScriptMap to add back in .svc (WCF Service) support
                {
                    List <object> values = new List <object>(pvc.Value as object[]);
                    bool          found  = false;

                    foreach (object value in values)
                    {
                        if ((value as string).StartsWith(".svc"))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Console.WriteLine(Strings.AddingSvcMapping);
                        values.Add(Strings._SvcScriptMapping);
                        pvc.Value = values.ToArray();
                        vdir.CommitChanges();
                    }
                }
            }
            vdir.Close();
            #endregion

            #region Add the MimeType mapping for .grproj
            PropertyValueCollection mimeMapCollection = site.Properties["MimeMap"]; // Can I just do this on the vdir I wonder...?
            foreach (IISOle.IISMimeType mimeType in mimeMapCollection)
            {
                if (mimeType.Extension == ".grproj")
                {
                    mimeMapCollection.Remove(mimeType);
                    break;
                }
            }

            IISOle.MimeMapClass mimeMapping = new IISOle.MimeMapClass();
            mimeMapping.Extension = ".grproj";
            mimeMapping.MimeType  = "x-ms-gravaproject";
            mimeMapCollection.Add(mimeMapping);
            site.CommitChanges();
            #endregion
        }