在IIS7.5中添加Web应用程序

在IIS7.5中添加Web应用程序,第1张

建立不同的Web应用程序可以在同一个网站中同时运行多个Web站点(VS中的网站),那么如何建立Web应用程序呢?下面我们一起学习一下吧。

工具/材料

已安装iis的Windows的电脑

01

选择“开始”→“控制面板”→“系统和安全”→“管理工具”→“Internet 信息服务(IIS)管理器”

02

展开“网站”,右击所添加的网站,此处为test,在d出的快捷菜单中选择“添加应用程序”。

03

在呈现的对话框中输入别名、物理路径、选择应用程序池。

04

单击“确定”按钮,即可看见网站中已添加该应用程序。

using System

using System.Collections.Generic

using System.Text

using System.DirectoryServices

using System.IO

using System.Security.AccessControl

using System.Data

using System.Data.SqlClient

using Microsoft.Web.Administration

namespace Setup

{

  public  class Win2008

    {

    //设置应用程序使用.NET4.0

      public static void EnableNet4()

      {

          try

          {

              using (ServerManager serverManager = new ServerManager())

              {

                  Configuration config = serverManager.GetApplicationHostConfiguration()

                  ConfigurationSection isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction")

                  ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection()

                  foreach (ConfigurationElement element in isapiCgiRestrictionCollection)

                  {

                      string path = element["path"].ToString()

                      string allowed = element["allowed"].ToString()

                      string description = element["description"].ToString()

                      string groupId = element["groupId"].ToString()

                      if (description == "ASP.NET v4.0.30319")

                      {

                        

                            element["allowed"] = true

                        

                      }

                  }

                  serverManager.CommitChanges()

              }

          }

          catch

          { 

          

          }

      }

       //删除应用程序

        public static bool DeleteVdir(string vDirName)

        {

            try

            {

                ServerManager serverManager = new ServerManager()

                Site mySite = serverManager.Sites["Default Web Site"]

                Microsoft.Web.Administration.Application application = mySite.Applications["/" + vDirName]

                mySite.Applications.Remove(application)

                serverManager.CommitChanges()

                return true

            }

            catch(Exception ex)

            {

                Common.WriteLog(ex.Message)

                return false

            }

        }

//添加应用程序,参数:vdir:应用程序名如 abc, phydir:物理路径 如 d:\xxx\www

        public static bool  CreateVdir(string vdir, string phydir)

        {

            try

            {

                ServerManager serverManager = new ServerManager()

                Site mySite = serverManager.Sites["Default Web Site"]

                mySite.Applications.Add("/" + vdir, phydir)

                serverManager.CommitChanges()

                return true

            }

            catch (Exception ex)

            {

                Common.WriteLog(ex.Message)

            

            }

            return false

        }

//删除应用程序池

        public static void DeleteAppPool(string appPoolName)

        {

            try

            {

              

                ServerManager serverManager = new ServerManager()

                ApplicationPool apppool = serverManager.ApplicationPools[appPoolName]

                serverManager.ApplicationPools.Remove(apppool)

                serverManager.CommitChanges()

            }

            catch(Exception ex)

            {

                Common.WriteLog(ex.Message)

            

            }

        }

//添加应用程序池,添加之前先删除

        public static void CreateAppPool( string appPoolName)

        {

            DeleteAppPool(appPoolName)

            try

            {

                ServerManager serverManager = new ServerManager()

                serverManager.ApplicationPools.Add(appPoolName)

                ApplicationPool apppool = serverManager.ApplicationPools[appPoolName]

                apppool.ManagedPipelineMode = ManagedPipelineMode.Integrated

                apppool.Enable32BitAppOnWin64 = true

                apppool.ManagedRuntimeVersion = "v4.0"

                serverManager.CommitChanges()

                apppool.Recycle()

            }

            catch(Exception ex)

            {

                Common.WriteLog(ex.Message)

            

            }

        }

//将站点分配到应用程序池

     public   static void AssignVDirToAppPool(string vdir, string appPoolName)

        {

            try

            {

                ServerManager serverManager = new ServerManager()

                Site site = serverManager.Sites["Default Web Site"]

                site.Applications["/" + vdir].ApplicationPoolName = appPoolName

                serverManager.CommitChanges()

            }

            catch(Exception ex)

            {

                Common.WriteLog(ex.Message)

            }

           

        }

 

    }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7761416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存