我的应用程序使用的是Nancy uses主机。当我在没有管理员权限的情况下启动它时,我得到一个System.Net.HttpListenerException“访问被拒绝”。
代码如下:
static void Main(string[] args)
{
var nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:80/"));
nancyHost.Start();
Application.Run();
}
我也尝试过不同的端口,但都没有成功。奇怪的是,当启动一个侦听相同网址的HttpListener时,我没有得到任何异常。导致此异常的原因可能是什么?
发布于 2013-08-26 14:44:15
您需要将自主机配置设置为不通过RewriteLocalhost
property重写本地主机路由。
namespace NancyApplication1
{
using System;
using Nancy.Hosting.Self;
class Program
{
static void Main(string[] args)
{
var uri = new Uri("http://localhost:3579");
var config = new HostConfiguration();
// (Change the default RewriteLocalhost value)
config.RewriteLocalhost = false;
using (var host = new NancyHost(config, uri))
{
host.Start();
Console.WriteLine("Your application is running on " + uri);
Console.WriteLine("Press any [Enter] to close the host.");
Console.ReadLine();
}
}
}
}
我通过尝试和失败发现了这一点,但是this page explains the reason behind.
发布于 2017-04-06 12:23:40
你可以用Kestrel招待南希。其实很简单:
public void Main(string[] args)
{
var owinHost = new WebHostBuilder()
.UseStartup<Startup>()
.UseUrls("http://+:12345/")
.Build();
owinHost.Run();
}
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseOwin(x => x.UseNancy());
}
}
唯一的困难是准备所有需要的dlls (30+)。我们绝对应该使用NuGet来解决所有的依赖关系。
https://stackoverflow.com/questions/16064732
复制相似问题