我有一个托管在 IIS 7.5 上的 C# Web 应用程序,
它运行 powershell 脚本来创建应用程序池和网站。
如果我从命令提示符运行 powershell 脚本,它可以工作,但是当我通过 C# 应用程序“Set-ItemProperty”运行它时,它不起作用。它也没有给出错误。
我找不到确切的问题,
请帮忙
PowerShell脚本
Import-Module WebAdministration -Force;
$siteName=$args[0];
$AppPoolName=$args[1];
$PortNumber=$args[2];
$PhysicalPath=$args[3];
New-Item IIS:\AppPools\$AppPoolName
Set-ItemProperty IIS:\AppPools\$AppPoolName managedRuntimeVersion v4.0
New-Item IIS:\Sites\$siteName -physicalPath $PhysicalPath$siteName -bindings @{protocol="http";bindingInformation=":"+$PortNumber+":"} -Force
Set-ItemProperty IIS:\Sites\$siteName -Name applicationPool -Value $AppPoolName -Force
C# code
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
var runSpaceInvoker = new RunspaceInvoke(runspace);
runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted -Scope Process -Force");
runSpaceInvoker.Invoke("Import-Module WebAdministration");
Pipeline pipeline = runspace.CreatePipeline();
var appPoolName = new CommandParameter(null, "test");
var siteName = new CommandParameter(null, "test");
var scriptPath = ConfigurationManager.AppSettings["PowershellSscriptRootPath"];
var websiteRootFolder = ConfigurationManager.AppSettings["PhysicalPathRoot"];
var websitePath = "C://inetpub//wwwroot//test";
#region CreateWebsite
string scriptPathForCreateWebsiteFromConfiguration = scriptPath + ConfigurationManager.AppSettings["CreateAppPoolScriptName"];
var createWebsiteCommand = new Command(scriptPathForCreateWebsiteFromConfiguration);
createWebsiteCommand.Parameters.Add(siteName);
createWebsiteCommand.Parameters.Add(appPoolName);
createWebsiteCommand.Parameters.Add(new CommandParameter(null, "80"));
createWebsiteCommand.Parameters.Add(new CommandParameter(null, websiteRootFolder));
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)