HttpListener訪問被拒絕我在C#中編寫HTTP服務(wù)器。當(dāng)我嘗試執(zhí)行該功能時(shí),HttpListener.Start()我得到一個(gè)HttpListenerException說(shuō)法“拒絕訪問”。當(dāng)我在Windows 7中以管理員模式運(yùn)行應(yīng)用程序時(shí),它工作正常。我可以在沒有管理員模式的情況下運(yùn)行嗎 如果有,怎么樣?如果不是,如何在開始運(yùn)行后讓應(yīng)用程序更改為管理模式?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;
}
}
}
}}
HttpListener訪問被拒絕
慕運(yùn)維8079593
2019-08-24 15:02:27