【发布时间】:2017-11-19 18:18:54
【问题描述】:
我有一个控制台应用程序,我想使用 Nancy 来托管 Web 服务。 这是我的 Program.cs
namespace NancyConsole
{
using Nancy.Hosting.Self;
using System;
internal class Program
{
private static void Main(string[] args)
{
string url = "http://localhost:1234";
var host = new NancyHost(new Uri(url));
host.Start();
Console.WriteLine("Server started, now listening on " + url);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
host.Stop();
}
}
}
这是我的 MainModule.cs 文件
namespace NancyConsole
{
using Nancy;
internal class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = x => View["Views/index.html"];
}
}
}
我不知道我哪里出错了?非常感谢您的帮助!
【问题讨论】:
-
您是否尝试以管理员身份运行。也许Vs没有保留端口。是否预留端口:netsh http add urlacl url = http://*:1234/ user=[USER]
-
我没有在VS上运行,我编译了解决方案然后我去Debug文件夹并以管理员身份运行exe
-
@MRsa 也可以将带有选项 RewriteLocalhost = false 的 HostConfiguration 传递给 NancyHost 构造函数,这样您就不需要设置 url acls。当然,这只会绑定本地主机,其他节点无法访问。
标签: c# nancy self-hosting