简体   繁体   English

南希自我托管者返回404

[英]Nancy self host returns 404

I have a console app which i want to use Nancy to host a web service. 我有一个控制台应用程序,我想使用Nancy托管Web服务。 here is my Program.cs 这是我的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();
        }
    }
}

and here is my MainModule.cs file 这是我的MainModule.cs文件

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

This is my project structure 这是我的项目结构 项目结构

When i run the project this is the error i get on the browser 当我运行项目时,这是我在浏览器上看到的错误 错误信息

I dont know where i am going wrong? 我不知道我要去哪里错了? Your help will be highly appreciated! 非常感谢您的帮助!

Make the module public. 将模块公开。 The default loading strategy uses reflection to find public module classes. 默认的加载策略使用反射来查找公共模块类。

public class MainModule : NancyModule

From the documentation : 文档中

It is important that you declare your module public, otherwise NancyFx is not able to discover your module. 将模块声明为公共很重要,否则NancyFx无法发现您的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM