好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#修改IIS站点framework版本号的方法

本文实例讲述了C#修改IIS站点framework版本号的方法。分享给大家供大家参考。具体如下:

使用ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以方便地更新 ASP.NET 应用程序的脚本映射,使其指向与该工具关联的 ASP.NET ISAPI 版本.

关于ASP.NET IIS 注册工具的更详细的内容,请参考MSDN.

在控制台上我们使用下面的命令可以修改一个虚拟目录的Asp.Net版本:

复制代码 代码如下:

Aspnet_iis.exe –s path

 

我们知道了如何来修改一个虚拟目录的版本,现在的问题就是如何使用程序来实现它了.

以下代码基于.Net FrameWork 2.0 在Windows Xp sp2中编译通过:

?

//创建一个虚拟目录

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#程序设计有所帮助。

dy("nrwz");

查看更多关于C#修改IIS站点framework版本号的方法的详细内容...

  阅读:74次