本文實例講述了C#修改IIS站點framework版本號的方法。分享給大家供大家參考。具體如下:
使用ASP.NET IIS 注冊工具 (Aspnet_regiis.exe)可以方便地更新 ASP.NET 應(yīng)用程序的腳本映射,使其指向與該工具關(guān)聯(lián)的 ASP.NET ISAPI 版本.
關(guān)于ASP.NET IIS 注冊工具的更詳細(xì)的內(nèi)容,請參考MSDN.
在控制臺上我們使用下面的命令可以修改一個虛擬目錄的Asp.Net版本:
我們知道了如何來修改一個虛擬目錄的版本,現(xiàn)在的問題就是如何使用程序來實現(xiàn)它了.
以下代碼基于.Net FrameWork 2.0 在Windows Xp sp2中編譯通過:
- //創(chuàng)建一個虛擬目錄
- DirectoryEntry dirRoot = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
- DirectoryEntries dirs = dirRoot.Children;
- DirectoryEntry virtualDir = dirs.Add("VirtualChange", dirRoot.SchemaClassName);
- object[] objs = new object[] { true };
- virtualDir.Invoke("AppCreate", objs);
- virtualDir.Properties["AppFriendlyName"][0] = "VirtualChange";
- virtualDir.Properties["Path"].Value = "C://VirtualChange";
- virtualDir.CommitChanges();
- //啟動aspnet_iis.exe程序
- string fileName = Environment.GetEnvironmentVariable("windir") + @"/Microsoft.NET/Framework/v1.1.4322/aspnet_regiis.exe";
- ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
- //處理目錄路徑
- string path = virtualDir.Path.ToUpper();
- 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());
希望本文所述對大家的C#程序設(shè)計有所幫助。
新聞熱點
疑難解答