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

发布于 2024-08-26 01:03:47 字数 52 浏览 4 评论 0原文

如何使用c#.net FROM CODE为所有iis版本设置虚拟目录的ASP.NET版本?

how to set ASP.NET version for virtual directory using c#.net FROM CODE for all iis version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2024-09-02 01:03:47

以下代码对我有用
stringphysicalPath="D:\SVN\Safetypad\SafetyPADUniversal";
System.EnterpriseServices.Internal.IISVirtualRoot vr = new 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();

the folllowing code worked out for me
string physicalPath ="D:\SVN\Safetypad\SafetyPADUniversal";
System.EnterpriseServices.Internal.IISVirtualRoot vr = new 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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文