为了账号安全,请及时绑定邮箱和手机立即绑定

HttpListener访问被拒绝

HttpListener访问被拒绝

慕运维8079593 2019-08-24 15:02:27
HttpListener访问被拒绝我在C#中编写HTTP服务器。当我尝试执行该功能时,HttpListener.Start()我得到一个HttpListenerException说法“拒绝访问”。当我在Windows 7中以管理员模式运行应用程序时,它工作正常。我可以在没有管理员模式的情况下运行吗 如果有,怎么样?如果不是,如何在开始运行后让应用程序更改为管理模式?using System;using System.Net;namespace ConsoleApplication1{     class Program     {         private HttpListener httpListener = null;         static void Main(string[] args)         {             Program p = new Program();             p.Server();         }         public void Server()         {             this.httpListener = new HttpListener();             if (httpListener.IsListening)                 throw new InvalidOperationException("Server is currently running.");             httpListener.Prefixes.Clear();             httpListener.Prefixes.Add("http://*:4444/");             try             {                 httpListener.Start(); //Throws Exception             }             catch (HttpListenerException ex)             {                 if (ex.Message.Contains("Access is denied"))                 {                     return;                 }                 else                 {                     throw;                 }             }         }     }}
查看完整描述

3 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

您可以通过设置IgnoreWriteExceptions来修复没有管理员权限的localhost:

listener.IgnoreWriteExceptions = True
listener.Start()


查看完整回答
反对 回复 2019-08-24
  • 3 回答
  • 0 关注
  • 1335 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信