本文将介绍一个方法用于修改虚拟目录的Asp.Net版本.
ASP.NET IIS 注册工具
使用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());
查看更多关于用程序修改IIS目录的Asp.Net版本的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did36461