南希自我托管者返回404

ind*_*ago 2 c# self-hosting nancy

我有一个控制台应用程序,我想使用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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的MainModule.cs文件

namespace NancyConsole
{
    using Nancy;
    internal class MainModule : NancyModule
    {
        public MainModule()
        {
            Get["/"] = x => View["Views/index.html"];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构 项目结构

当我运行项目时,这是我在浏览器上看到的错误 错误信息

我不知道我要去哪里错了?非常感谢您的帮助!

Mik*_*ray 5

将模块公开。默认的加载策略使用反射来查找公共模块类。

public class MainModule : NancyModule
Run Code Online (Sandbox Code Playgroud)

文档中

将模块声明为公共很重要,否则NancyFx无法发现您的模块。