Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用.NET设置虚拟目录的ASP.NET版本_C#_.net_Iis_Virtual Directory - Fatal编程技术网

C# 如何使用.NET设置虚拟目录的ASP.NET版本

C# 如何使用.NET设置虚拟目录的ASP.NET版本,c#,.net,iis,virtual-directory,C#,.net,Iis,Virtual Directory,如何使用c#.NET从代码为所有iis版本设置虚拟目录的ASP.NET版本 下面的代码适合我 string physicalPath=“D:\SVN\Safetypad\SafetyPADUniversal”; System.EnterpriseServices.Internal.IISVirtualRoot vr=新的System.EnterpriseServices.Internal.IISVirtualRoot() string sError = "";

如何使用c#.NET从代码为所有iis版本设置虚拟目录的ASP.NET版本

下面的代码适合我 string physicalPath=“D:\SVN\Safetypad\SafetyPADUniversal”; System.EnterpriseServices.Internal.IISVirtualRoot vr=新的System.EnterpriseServices.Internal.IISVirtualRoot()

        string sError = "";

        string VDName = "MY";

        vr.Create("IIS://localhost/W3SVC/1/Root", physicalPath, VDName, out sError);


        if (sError.Trim().Length > 0)
            throw new Exception("Error when creating Virtual Directory:" + Environment.NewLine + sError);

        DirectoryEntry deVDir = new DirectoryEntry("IIS://localhost/W3SVC/1/Root/" + VDName);
        deVDir.Properties["Path"].Value = physicalPath;

        deVDir.Properties["DefaultDoc"].Value = "Mainscreen1.aspx";
        foreach (PropertyValueCollection val in deVDir.Properties)
        {
            Console.WriteLine(val.PropertyName);
        }


        PropertyValueCollection vals = deVDir.Properties["ScriptMaps"];
        ArrayList objScriptMaps = new ArrayList();

                  objScriptMaps.Add(val.Replace(version,frameworkVersion));



        string _frameWorkDir;
        string _Dir;
        string _FrameWorkVersion = "2.0.50727";
        _Dir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
        int dirpos = _Dir.Remove(_Dir.Length - 1, 1).LastIndexOf(@"\");
        _frameWorkDir = _Dir.Remove(dirpos, _Dir.Length - dirpos);
        _frameWorkDir = _frameWorkDir + @"\v" + _FrameWorkVersion + @"\";

        Process pro = new Process();
        pro.StartInfo.UseShellExecute = false;
        pro.StartInfo.RedirectStandardOutput = true;
        pro.StartInfo.RedirectStandardError = true;
        pro.StartInfo.FileName = _frameWorkDir + "aspnet_regiis";
       pro.StartInfo.Arguments = @"-s " + @"/W3SVC/1/Root/";

        pro.Start();
        pro.WaitForExit();