Nancy无法在自定义约定中找到静态内容

Iai*_*oat 6 nancy

我已经设置了一个Nancy bootstrapper来提供来自非默认目录路径的静态内容(它是自托管的Nancy).

奇怪的是,以下内容适用于自定义View位置约定,但不适用于js或css静态内容约定(是的,这些位置都存在文件和文件夹!).我尝试解决此问题的尝试进一步复杂化,因为我还没有想出如何记录未找到静态内容时发生的错误.

using System;
using System.IO;

using Nancy;
using Nancy.Conventions;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;

namespace MyApp
{
    public class ApplicationBootstrapper : DefaultNancyBootstrapper
    {

    private const string RELATIVE_PATH_TO_SOURCE = @"../static/MyApp/";

    protected override void ConfigureConventions(NancyConventions nancyConventions)
    {

        nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("js", string.Concat(RELATIVE_PATH_TO_SOURCE, "Scripts/")));
        nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("css", string.Concat(RELATIVE_PATH_TO_SOURCE, "Content/")));
        this.Conventions.ViewLocationConventions.Add((viewName, model, context) =>
        {
            return string.Concat(RELATIVE_PATH_TO_SOURCE, "Views/", viewName);
        });
        this.Conventions.ViewLocationConventions.Add((viewName, model, context) =>
        {
            return string.Concat(RELATIVE_PATH_TO_SOURCE, "Views/", context.ModuleName, "/", viewName);
        });

        base.ConfigureConventions(nancyConventions);
    }

    protected override IRootPathProvider RootPathProvider
    {
        get
        {
            return new MyRootPathProvider();
        }
    }

    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
    {
        pipelines.OnError += (ctx, ex) =>
        {
            Console.WriteLine("RootPath : {0}", DebugRootPathProvider.RootPath);
            Console.WriteLine("Unhandled error on request: {0} : {1}", ctx.Request.Url, ex.Message); //HACK
            Console.WriteLine(ex.StackTrace); //HACK poor man's logging
            return null;
        };
    }
}

public class MyRootPathProvider : IRootPathProvider
{
    public static readonly string RootPath;
    static MyRootPathProvider()
    {
        RootPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    }

    public string GetRootPath()
    {
        return RootPath;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Chrome和ProcMon的输出如下: ProcMon输出 谷歌Chrome输出

我应该怎么做:

  1. 未找到js和css文件时发生日志错误?
  2. 使用静态文件约定解决404错误?

Jus*_*ing 3

您可以使用sysinternals 进程监视器来查找 nancy 进程(exe 或 IIS 工作进程)尝试读取的文件,而不是记录日志。