2

我在我的控制台应用程序中托管 Nancy,当我尝试调用视图(例如“Login.html”)时,页面给了我错误 500。这是代码:

public sealed class LoginModule : NancyModule
{
    private readonly DatabaseList _db = Singleton.DB;
    public LoginModule()
    {
        Get["/"] = x => View["Login.html"];
    }
}

我实现了自己的引导程序,因为我需要会话:

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
    {
        var directoryInfo = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
        if (directoryInfo != null)
            Environment.CurrentDirectory = directoryInfo.FullName;
        CookieBasedSessions.Enable(pipelines);
        Conventions.ViewLocationConventions.Add((viewName, model, viewLocationContext) => String.Concat("Views/", viewName));
    }
}

这是我项目的树:各种路径;

  • 网络控制器/
    • 登录模块.cs
    • 南希.cs
  • 观看次数/
    • 登录.html

我尝试删除所有删除 CurrentDirectory、ViewLocationConventions、每种类型的路径(如 /Views/、../Views/ 等)的组合,但仍然没有。我还尝试将 Views 路径放在 WebControllers 中,甚至只放在 Index.html 文件中,仍然没有。总之,我也尝试将 Views 重命名为 Login,无事可做。

4

1 回答 1

3

确保您的视图文件设置为复制到输出文件夹,您应该一切顺利

于 2013-04-12T05:22:45.643 回答