HttpListener访问被拒绝

编程入门 行业动态 更新时间:2024-10-27 01:32:59
本文介绍了HttpListener访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在C#中编写HTTP服务器。

I am writing an HTTP server in C#.

当我尝试执行函数 HttpListener.Start()我得到 HttpListenerException 说

When I try to execute the function HttpListener.Start() I get an HttpListenerException saying

拒绝访问 >

"Access Denied".

在Windows 7中以管理员模式运行应用程序时,它运行正常。

When I run the app in admin mode in windows 7 it works fine.

我可以让它运行没有管理模式?如果是如何? 如果没有,如何才能使应用程序在开始运行后更改为管理模式?

Can I make it run without admin mode? if yes how? If not how can I make the app change to admin mode after start running?

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("*:4444/"); try { httpListener.Start(); //Throws Exception } catch (HttpListenerException ex) { if (ex.Message.Contains("Access is denied")) { return; } else { throw; } } } } }

推荐答案

是的,您可以在非管理模式下运行HttpListener。所有您需要做的是授予对特定URL的权限。例如

Yes you can run HttpListener in non-admin mode. All you need to do is grant permissions to the particular URL. e.g.

netsh http add urlacl url=+:80/MyUri user=DOMAIN\user

文档这里。

更多推荐

HttpListener访问被拒绝

本文发布于:2023-10-13 00:33:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被拒   HttpListener

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!