举一些C#操作IIS代码

2016-02-19 12:26 26 1 收藏

下面图老师小编要向大家介绍下举一些C#操作IIS代码,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - 编程语言 】

 using System;
using System.DirectoryServices;
using System.Collections;

namespace OPS.Component
{
    /**//// summary
    /// IISWebServer的状态
    /// /summary
    public enum IISServerState
    {
        /**//// summary
        /// 
        /// /summary
        Starting = 1,
        /**//// summary
        /// 
        /// /summary
        Started = 2,
        /**//// summary
        /// 
        /// /summary
        Stopping = 3,
        /**//// summary
        /// 
        /// /summary
        Stopped = 4,
        /**//// summary
        /// 
        /// /summary
        Pausing = 5,
        /**//// summary
        /// 
        /// /summary
        Paused = 6,
        /**//// summary
        /// 
        /// /summary
        Continuing = 7
    }
}

 using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using System.DirectoryServices;

namespace OPS.Component
{
    /**//// summary
    /// IISWebServer
    /// /summary
    public class IISWebServer
    {
        /**//**/
        /**//// summary
        /// 
        /// /summary
        internal int index = -1;
        /**//**/
        /**//// summary
        /// 
        /// /summary
        public IISWebVirtualDirCollection WebVirtualDirs;
        /**//**/
        /**//// summary
        /// 网站说明
        /// /summary
        public string ServerComment = "Way";
        /**//**/
        /**//// summary
        /// 脚本支持
        /// /summary
        public bool AccessScript = true;
        /**//**/
        /**//// summary
        /// 读取
        /// /summary
        public bool AccessRead = true;
        /**//**/
        /**//// summary
        /// 物理路径
        /// /summary
        public string Path = @"c:";
        /**//**/
        /**//// summary
        /// 端口
        /// /summary
        public int Port = 80;
        /**//**/
        /**//// summary
        /// 目录浏览
        /// /summary
        public bool EnableDirBrowsing = false;
        /**//**/
        /**//// summary
        /// 默认文档
        /// /summary
        public string DefaultDoc = "index.aspx";
        /**//**/
        /**//// summary
        /// 使用默认文档
        /// /summary
        public bool EnableDefaultDoc = true;

        /**//**/
        /**//// summary
        /// IISWebServer的状态
        /// /summary
        public IISServerState ServerState
        {
            get
            {
                DirectoryEntry server = IISManagement.returnIISWebserver(this.index);
                if (server == null)
                    throw (new Exception("找不到此IISWebServer"));
                switch (server.Properties["ServerState"][0].ToString())
                {
                    case "2":
                        return IISServerState.Started;
                    case "4":
                        return IISServerState.Stopped;
                    case "6":
                        return IISServerState.Paused;
                }
                return IISServerState.Stopped;
            }
        }

        /**//**/
        /**//// summary
        /// 停止IISWebServer
        /// /summary
        public void Stop()
        {
            DirectoryEntry Server;
            if (index == -1)
                throw (new Exception("在IIS找不到此IISWebServer!"));
            try
            {
                Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
                if (Server != null)
                    Server.Invoke("stop", new object[0]);
                else
                    throw (new Exception("在IIS找不到此IISWebServer!"));
            }
            catch
            {
                throw (new Exception("在IIS找不到此IISWebServer!"));
            }
        }

        /**//**/
        /**//// summary
        /// 把基本信息的更改更新到IIS
        /// /summary
        public void CommitChanges()
        {
            IISManagement.EditIISWebServer(this);
        }

        /**//**/
        /**//// summary
        /// 启动IISWebServer
        /// /summary
        public void Start()
        {
            if (index == -1)
                throw (new Exception("在IIS找不到此IISWebServer!"));

            DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
            DirectoryEntry Server;
            IEnumerator ie = Service.Children.GetEnumerator();

            while (ie.MoveNext())
            {
                Server = (DirectoryEntry)ie.Current;
                if (Server.SchemaClassName == "IIsWebServer")
                {
                    if (Server.Properties["Serverbindings"][0].ToString() == ":" + this.Port + ":")
                    {
                        Server.Invoke("stop", new object[0]);
                    }
                }
            }

            try
            {
                Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
                if (Server != null)
                    Server.Invoke("start", new object[0]);
                else
                    throw (new Exception("在IIS找不到此IISWebServer!"));
            }
            catch
            {
     &n

来源:http://www.tulaoshi.com/n/20160219/1600888.html

延伸阅读
怎样取得一个字符串在另外一个字符串中出现的次数? PublicFunctionsCount(String1AsString,String2AsString)AsInteger DimIAsInteger,iCountAsInteger I=1 Do If(ILen(String1))ThenExitDo I=InStr(I,String1,String2,vbTextCompare) IfIThen iCount=iCount 1 I=I 2 DoEvents EndIf LoopWhile...
标签: Web开发
偶也不知道算不算,反正我自己随时写的用,很粗浅的,适合跟我一样的新手收藏,指不定就用得上呢! 一组是我这两天写留言本的 另组是以前VS2003写投票用的 高手看见的话,麻烦把好的解决方案说下,谢谢哦!!新手的话,共同学习了!! --------下面是我最近写个留言本用的------------     public s...
标签: Web开发
getElementById(id) getElementsByName(name) getElementsByTagName(tagname) appendChild(node) removeChild(childreference) cloneNode(deepBoolean) replaceChild(newChild, oldChild)
string str="wecncnc"; str+="wecncnc"; Regex re = new Regex(@"
private void Button1_Click(object sender, System.EventArgs e) { // Catalog Name string strCatalog = "TestCatalog"; string strQuery=""; strQuery = "Select DocTitle,Filename,Size,PATH,URL from Scope() where FREETEXT('" +TextBox1.Text+ "')"; // TextBox1.Text is the word that you type in the text box to query by using In...

经验教程

114

收藏

86
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部