服务器中是否有启用Websocket协议的注册表项可以检查? [已关闭]

问题描述 投票:0回答:1

我需要检查服务器是否具有服务器功能:

websocket protocol enabled
。 有这方面的注册表条目吗? 我似乎找不到这个问题的答案。 我需要通过我的代码进行检查。

c# websocket server
1个回答
0
投票

检查服务器

根据微软

  • 打开 Internet 信息服务 (IIS) 管理器:

  • 如果您使用的是 Windows Server 2012 或更高版本:

    • 在任务栏上,单击服务器管理器,单击工具,然后单击 Internet 信息服务 (IIS) 管理器。
  • 如果您使用的是 Windows 8 或更高版本:

    • 按住 Windows 键,按字母 X,然后单击 Control 控制板。单击“管理工具”,然后双击“Internet” 信息服务 (IIS) 经理。
  • 在“连接”窗格中,选择 用于为服务器配置 WebSocket 的服务器名称,或展开 站点,然后选择一个站点来为该站点配置 WebSocket,或者 展开站点,然后选择一个应用程序来配置 WebSocket 申请。

    • 在主页窗格中,双击配置编辑器功能。

    • 对于站点或应用程序,选择 web.config 或 From 文本框中的 applicationHost.config。

    • 在部分文本框中选择system.webServer/webSocket。

    • 将enabled设置为True以启用webSocket或设置为False以禁用 webSocket。将 pingInterval 和 receiveBufferLimit 设置为所需的值 价值观。

通过C#检查

选项 1:Powershell

using System.Management.Automation;

using (PowerShell ps = PowerShell.Create())
        {
            ps.AddCommand("Get-WindowsFeature")
              .AddParameter("Name", "Web-WebSockets");

            var result = ps.Invoke();

            // Check if there is a result and if 'Installed' is true
            if (result.Count > 0)
            {
                var feature = result[0].Properties["Installed"].Value;
                return (bool)feature;
            }

            return false;
        }

选项 2:DSIM

using System.Diagnostics;        
    {
        // Initialize a process to run the DISM command
        Process process = new Process();
        process.StartInfo.FileName = "dism";
        process.StartInfo.Arguments = "/online /get-features /format:table";
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;

        // Start the process
        process.Start();

        // Read the output
        string output = process.StandardOutput.ReadToEnd();
        process.WaitForExit();

        // Look for the Web-WebSockets feature in the output
        return output.Contains("Web-WebSockets") && output.Contains("Enabled");
    }
© www.soinside.com 2019 - 2024. All rights reserved.