asp.net – 如何使用Inno Setup脚本创建IIS应用程序和应用程序池
发布时间:2020-12-31 01:09:32  所属栏目:asp.Net  来源:互联网 
            导读:我试图使用Inno Setup部署一个ASP.NET应用程序. 我需要执行以下任务: 创建IIS应用程序. 创建一个新的IIS应用程序池,并将它的.NET版本设置为4. 将新应用程序的应用程序池设置为新的应用程序池. 我已经找到一个脚本来创建虚拟目录,但是我需要一个应用程序和应
                
                
                
            | 
                         我试图使用Inno Setup部署一个ASP.NET应用程序. 我需要执行以下任务: >创建IIS应用程序. 我已经找到一个脚本来创建虚拟目录,但是我需要一个应用程序和应用程序池: procedure CreateIISVirtualDir();
var
  IIS,WebSite,WebServer,WebRoot,VDir: Variant;
  ErrorCode: Integer;
begin
  { Create the main IIS COM Automation object }
  try
    IIS := CreateOleObject('IISNamespace');
  except
    RaiseException(
      'Please install Microsoft IIS first.'#13#13'(Error ''' +
      GetExceptionMessage + ''' occurred)');
  end;
  { Connect to the IIS server }
  WebSite := IIS.GetObject('IIsWebService',IISServerName + '/w3svc');
  WebServer := WebSite.GetObject('IIsWebServer',IISServerNumber);
  WebRoot := WebServer.GetObject('IIsWebVirtualDir','Root');
  { (Re)create a virtual dir }
  try
    WebRoot.Delete('IIsWebVirtualDir','eipwebv4');
    WebRoot.SetInfo();
  except
  end;
  VDir := WebRoot.Create('IIsWebVirtualDir','eipwebv4');
  VDir.AccessRead := True;
  VDir.AccessScript := TRUE;
  VDir.AppFriendlyName := 'Easy-IP Web Client';
  VDir.Path := ExpandConstant('{app}');
  try
    VDir.AppPoolId := 'Classic .NET AppPool';
  except
  end;
  VDir.AppCreate(True);
  VDir.SetInfo();
end;
解决方法这个问题很久以前被问到,但也许有人会发现IIS6 / IIS7的这个脚本很有用:var
  global_AppCmdFilePath :String;
  global_IsIIS7 :Boolean;
  global_WebSites :SiteList;
  global_WebSiteName :String;
  global_vDir :String;
  global_AppCmdExitCode :Integer;
const
  IISServerName = 'localhost';
  IISApplicationPoolName = 'Test Pool';
  ERROR_NOT_FOUND = 1168;
  ERROR_NOT_SUPPORTED = 50;
  MD_APPPOOL_IDENTITY_TYPE_LOCALSYSTEM = 0;
  MD_APPPOOL_IDENTITY_TYPE_LOCALSERVICE = 1;
  MD_APPPOOL_IDENTITY_TYPE_NETWORKSERVICE = 2;
  MD_APPPOOL_IDENTITY_TYPE_SPECIFICUSER = 3;
  MD_LOGON_INTERACTIVE = 0;
  MD_LOGON_BATCH = 1;
  MD_LOGON_NETWORK = 2;
  MD_LOGON_NETWORK_CLEARTEXT = 3;
function ExecAppCmd(params :String) :Boolean;
var
  execSuccessfully :Boolean;
  resultCode :Integer;
begin
  execSuccessfully := Exec('cmd.exe','/c ' + global_AppCmdFilePath + ' ' + params,'',SW_HIDE,ewWaitUntilTerminated,resultCode);
  global_AppCmdExitCode := resultCode;
  Result := execSuccessfully and (resultCode = 0);
end;
function CreateVirtualDirectoryForIIS6(physicalPath :String) :String;
var
  IIS,webService,webServer,webRoot,vDir,vDirApp :Variant;
  appPools,appPool :Variant;
  webSiteId :String;
begin
  webSiteId := GetWebSiteIdByName(global_WebSiteName);
  { Create the main IIS COM Automation object. }
  IIS := CreateOleObject('IISNamespace');
  { Get application pools. }
  appPools := IIS.GetObject('IIsApplicationPools','localhost/W3SVC/AppPools');
  try
    { Check if the application pool already exists. }
    appPool := appPools.GetObject('IIsApplicationPool',IISApplicationPoolName);
  except
    { Crete the application pool. }
    try
      appPool := appPools.Create('IIsApplicationPool',IISApplicationPoolName);
      appPool.LogonMethod := MD_LOGON_NETWORK_CLEARTEXT;
      appPool.AppPoolIdentityType := MD_APPPOOL_IDENTITY_TYPE_NETWORKSERVICE;
      appPool.SetInfo();
    except
      Result := 'Failed to create an apllication pool.';
      Exit;
    end;
  end;
  { Connect to the IIS server. }
  webService := IIS.GetObject('IIsWebService',IISServerName + '/w3svc');
  { Get the website. }
  webServer := webService.GetObject('IIsWebServer',webSiteId);
  webRoot := webServer.GetObject('IIsWebVirtualDir','Root');
  { Delete the virtual dir if it already exists. }
  try
    webRoot.Delete('IIsWebVirtualDir',global_vDir);
    webRoot.SetInfo();
  except
    { An exception will be raised if there is not such a website. }
  end;
  { Create the virtual directory. }
  try
    vDir := WebRoot.Create('IIsWebVirtualDir',global_vDir);
    vDir.AccessRead := True;
    vDir.AccessScript := True;
    vDir.AppFriendlyName := 'Test friendly name';
    vDir.Path := physicalPath;
    vDir.AppCreate(False);
    vDir.SetInfo();
  except
    Result := 'Failed to create a virtual directory.';
    Exit;
  end;
  { Assign the application pool to the virtual directory. }
  try
    vDir := webRoot.GetObject('IIsWebVirtualDir',global_vDir);
    vDir.AppPoolId := IISApplicationPoolName;
    vDir.SetInfo();
  except
    Result := 'Failed to assign the application pool to the virtual directory.';
    Exit;
  end;
end;
function CreateVirtualDirectoryForIIS7(physicalPath :String) :String;
var
  tempFileName :String;
  appPoolList :String;
  createAppPool :Boolean;
begin
  { Delete the application if it already exists. }
  if not ExecAppCmd(Format('delete app "%s/%s"',[global_WebSiteName,global_vDir])) then
  begin
    if (global_AppCmdExitCode <> ERROR_NOT_FOUND) and (global_AppCmdExitCode <> ERROR_NOT_SUPPORTED) then
    begin
      Result := 'Failed to delete the application.  ' + GetErrorMessageByCode(global_AppCmdExitCode);
      Exit;
    end;
  end;
  { Check if the application pool already exists. }
  tempFileName := ExpandConstant('{tmp}AppPoolNames.txt');
  ExecAppCmd(Format('list apppool "%s" > "%s"',[IISApplicationPoolName,tempFileName]));
  if (LoadStringFromFile(tempFileName,appPoolList)) then
  begin
    createAppPool := (Pos(IISApplicationPoolName,appPoolList) = 0);
  end
  else
  begin
    createAppPool := True;
  end;
  { Create the application pool. }
  if (createAppPool) then
  begin
    if not ExecAppCmd(Format('add apppool /name:"%s" /managedRuntimeVersion:v4.0',[IISApplicationPoolName])) then
    begin
      Result := 'Failed to add the application pool. ' + GetErrorMessageByCode(global_AppCmdExitCode);
      Exit;
    end;
  end;
  { Create the application. }
  if not ExecAppCmd(Format('add app /site.name:"%s" /path:"/%s" /physicalPath:"%s" /applicationPool:"%s"',global_vDir,physicalPath,IISApplicationPoolName])) then
  begin
    Result := 'Failed to add the application. ' + GetErrorMessageByCode(global_AppCmdExitCode);
    Exit;
  end;
  Result := '';
end;                        (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- asp.net-mvc – 使用AD的ASP.NET MVC表单Auth在本地工作但在
 - asp.net-mvc-3 – 在MVC Razor View中使用If语句
 - asp.net编程实现删除文件夹及文件夹下文件的方法
 - 将ASP.NET身份与核心域模型分离 – 洋葱架构
 - asp.net-mvc-3 – MVC3剃须刀:是否可以渲染传统的ASCX?
 - ASP.NET虚拟路径映射到另一个不允许的应用程序
 - asp.net-mvc – 在MVC Controller中访问GET参数
 - asp.net-core – 如何在ASP.NET 5中使用“旧”依赖项
 - asp.net – 我可以重新发布或携带POST数据(如果是这样,我可
 - 什么是在asp.net中301重定向更推荐的方法?
 
推荐文章
            站长推荐
            - asp.net – 如何在gridview中将navigateurl添加到
 - ASP.Net中的图形(c#)
 - asp.net-mvc-3 – 如何避免使用MVC3 FileContent
 - asp.net-mvc – 如何检查是否为浏览器启用了cook
 - asp.net – 如何从TableAdapter中检索存储过程返
 - asp.net-mvc – 如何在ASP.NET MVC4中使用具有唯
 - asp.net中的GridView分页问题
 - asp.net – 如何查看Chrome开发者工具中发布到表
 - asp.net core标签助手的高级用法TagHelper+Form
 - asp.net – 从启用AJAX的WCF服务返回错误详细信息
 
热点阅读
            