string fileName = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe";//v2.0.50727為要設置的asp.net版本號如果是asp.net1.1請改為v1.1.4322
ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
//处理目录路径
string path ="要設置的網站或虛擬目錄的路徑,如W3SVC/1/ROOT/EHRSNET"
int index = path.IndexOf("W3SVC");
path = path.Remove(0, index);
//启动aspnet_iis.exe程序,刷新教本映射
startInfo.Arguments = "-s " + path;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
string errors = process.StandardError.ReadToEnd();
if (errors != string.Empty)
throw new Exception(errors);
Console.WriteLine(process.StandardOutput.ReadToEnd());
|