IIS 站点管理Api

本文介绍了如何利用Microsoft.Web.Administration DLL进行IIS站点的管理,但提到了在获取FTP状态时可能会遇到错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

引用 Microsoft.Web.Administration Dll 就行;

注意获取Ftp的状态会报错

using Microsoft.Web.Administration;
using Newtonsoft.Json;
using ReleaseManagement.Common;
using ReleaseManagement.Converter;
using ReleaseManagement.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.DirectoryServices;
using System.Linq;
using System.Web;

namespace ReleaseManagement.Service
{
    public class IISManager
    {

        /// <summary>
        /// 创建一个站点
        /// </summary>
        /// <param name="name">站点名称</param>
        /// <param name="physicalPath">项目所在路径</param>
        /// <param name="bindingInformation">绑定信息</param>
        /// <param name="bindingProtocol">类型,默认http</param>
        /// <returns></returns>
        public static ResultCommon CreateWebSite(string name,
            string physicalPath,
             string hostName,
            string prot = "80",
            string ip = "*",
            string bindingProtocol = "http")
        {
            ResultCommon resultCommon = new ResultCommon();
            try
            {
                ServerManager manager = new ServerManager();
                //判断web应用程序是否存在
                if (manager.Sites[name] != null || manager.ApplicationPools[name] != null)
                {
                    throw new Exception("该站点已存在");
                    //resultCommon.fail("该站点已存在");
                }
                string bindingInformation = ip + ":" + prot + ":" + hostName;
                manager.Sites.Add(name, bindingProtocol, bindingInformation, physicalPath);
                //添加web应用程序池
                ApplicationPool pool = manager.ApplicationPools.Add(name);
                //设置web应用程序池的Framework版本
                pool.ManagedRuntimeVersion = "v4.0";
                //设置是否启用32位应用程序
                pool.SetAttributeValue("enable32BitAppOnWin64", true);
                //设置web网站的应用程序池
                manager.Sites[name].Applications[0].ApplicationPoolName = name;
                manager.CommitChanges();

                return resultCommon.success();
            }
            catch (Exception e)
            {
                throw new Exception(""+ e.Message);
                // return resultCommon.fail(e.Message);
            }
        }

        /// <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值