代码之家  ›  专栏  ›  技术社区  ›  indago

Nancy self host返回404

  •  3
  • indago  · 技术社区  · 7 年前

    我有一个控制台应用程序,我想使用Nancy托管一个web服务。 这是我的 程序反恐精英

    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();
            }
        }
    }
    

    这是我的 主模块。反恐精英 文件

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

    The project structure

    当我运行项目时,这是我在浏览器上遇到的错误 Error Message

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

    1 回复  |  直到 7 年前
        1
  •  6
  •   Mike Zboray    7 年前

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

    public class MainModule : NancyModule
    

    documentation

    您必须将模块声明为公共的,否则NancyFx无法发现您的模块。