加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – .NET Core中HttpListener的模拟内容

发布时间:2020-12-15 18:29:33 所属栏目:百科 来源:网络整理
导读:我将应用程序从.NET 4移植到.NET Core,无法找到HttpListener类的模拟 Error CS0246 The type or namespace name 'HttpListener' could not be found (are you missing a using directive or an assembly reference?) UPDATE1 private readonly HttpListener
我将应用程序从.NET 4移植到.NET Core,无法找到HttpListener类的模拟
Error   CS0246  The type or namespace name 'HttpListener' could not be found (are you missing a using directive or an assembly reference?)

UPDATE1

private readonly HttpListener _httpListener;

            if (!HttpListener.IsSupported)
        {
            throw new NotSupportedException(
                "The Http Server cannot run on this operating system.");
        }

        _httpListener = new HttpListener();
        _httpListener.Prefixes.Add(prefix);
        _sessionSettings = settings;

解决方法

正如评论中所提到的,WebListener(在Microsoft.Net.Http.Server NuGet包中)是最接近的替代品,但具有不同的API.或者,还有Kestrel HTTP服务器,它最好从ASP.NET Core堆栈中使用,但可以单独使用(但很难设置).

如果您正在移植,我建议等到.NET Core 2.0,它具有兼容API的HttpListener,可以跨平台工作,并且不需要您完全更改代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读