5

我正在尝试利用 NancyFX 的嵌入式视图功能,但无法实现。我用过那个例子。但是,看起来南希并没有ResourceViewLocationProvider用来定位我的视图。

我的引导程序配置,

    protected override void ConfigureApplicationContainer(IKernel existingContainer)
    {
        base.ConfigureApplicationContainer(existingContainer);

        var currentAssembly = GetType().Assembly;
        ResourceViewLocationProvider.RootNamespaces.Add(currentAssembly, "Candidate.Nancy.SelfHosted.Views");
    }

    protected override NancyInternalConfiguration InternalConfiguration
    {
        get { return NancyInternalConfiguration.WithOverrides(x => x.ViewLocationProvider = typeof(ResourceViewLocationProvider)); }
    }

我的模块,

public class AccountModule : NancyModule
{
    private readonly IUserManagement _userManagement;

    public AccountModule(IUserManagement userManagement) : base("/account")
    {
        _userManagement = userManagement;
        Get["/login"] = p => View["Login.cshtml"];
    }
}

Login.cshtml 放在 /Views/Account/Login.cshtml 下并标记为嵌入资源。

如果我运行应用程序,我会得到 HTTP 500。在我看来,它试图在文件系统而不是程序集资源上找到它。

Nancy.RequestExecutionException:哦,不!---> Nancy.ViewEngines.ViewNotFoundException:无法找到视图“Login.cshtml”当前可用的视图引擎扩展:sshtml、html、htm、cshtml、vbhtml 检查的位置:Login.cshtml、views/Login.cshtml、views/account /Login.cshtml,account/Login.cshtml,views/Account/Login.cshtml,Account/Login.cshtml 根路径:D:\Development\Projects\candidate.net\src\Candidate.Nancy.Selfhosted\bin\Debug at Nancy.ViewEngines.DefaultViewFactory.GetRenderedView(String viewName, Object model, ViewLocationContext viewLocationContext) at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,Tret](CallSite 站点, T0 arg0, T1 arg1, T2 arg2, T3 arg3) 在 Nancy.ViewEngines.DefaultViewFactory.RenderView(String viewName, Object model,
在 Nancy.NancyEngine.ResolveAndInvokeRoute(NancyContext context) 在 Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, IPipelines pipelines) --- 内部异常堆栈跟踪结束 ---
在 Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex )

更新:此问题已在 Nancy 0.12.1.0 中解决。

4

0 回答 0