0
votes

I have a very simple module and view setup in NancyFx, such as this;

public class LoginModule : NancyModule
{
    public LoginModule()
    {
        Get["/login"] = _ => View["login", null];
    }        
}

The view for this page is located in project\views\login\login.cshtml.

I've configured a custom view convention to try and solve the problem, e.g.

nancyConventions.ViewLocationConventions.Clear();
nancyConventions.ViewLocationConventions.Add((viewName, model, viewLocationContext) => string.Concat("views/", viewName));
nancyConventions.ViewLocationConventions.Add((viewName, model, viewLocationContext) => string.Concat("views/", viewLocationContext.ModuleName, "/", viewName));

I'm using Owin (Nancy and Microsoft packages with the ASP.NET hosting package) to manage my web api layer.

The application works just fine when tested locally, but fails when deployed to Azure.

Nancy.RequestExecutionException: Oh noes! ---> Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'login' Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml Locations inspected: views/login,views/Login/login

Note it's logged the exact folder structure of my views, but for some reason, couldn't find the view file. It's noted the supported view files, so has picked up the Razor package.

It all works if I move the view files into the \views folder, but I'd like to logically separate the files if I can.

The projects are split with the Project.Web project referencing Project.WebApi (the Owin project where the Nancy bootstrapper is defined).

In response to another post here I added the Owin hander to the Project.Web web.config file.

<handlers>
  <add name="Owin" verb="*" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb" />
  <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</handlers>

But no success.

1
In addition I've created a custom RootPathProvider that works OK locally, but still fails on under Azure. The root path is defined as; D:\home\site\wwwroot.Aaron

1 Answers

1
votes

The problem was simply that the HTML files, .cshtml, needed the Build Action in the file properties changed from None to Content before they'll be published.

Working as documented here;

None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.