首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >没有管理员权限无法启动nancy self主机

没有管理员权限无法启动nancy self主机
EN

Stack Overflow用户
提问于 2013-04-17 23:54:50
回答 2查看 8.3K关注 0票数 18

我的应用程序使用的是Nancy uses主机。当我在没有管理员权限的情况下启动它时,我得到一个System.Net.HttpListenerException“访问被拒绝”。

代码如下:

代码语言:javascript
复制
static void Main(string[] args)
    {   
        var nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:80/"));
        nancyHost.Start();
        Application.Run();
    }

我也尝试过不同的端口,但都没有成功。奇怪的是,当启动一个侦听相同网址的HttpListener时,我没有得到任何异常。导致此异常的原因可能是什么?

EN

回答 2

Stack Overflow用户

发布于 2013-08-26 14:44:15

您需要将自主机配置设置为不通过RewriteLocalhost property重写本地主机路由。

代码语言:javascript
复制
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.

票数 47
EN

Stack Overflow用户

发布于 2017-04-06 12:23:40

你可以用Kestrel招待南希。其实很简单:

代码语言:javascript
复制
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来解决所有的依赖关系。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16064732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档