NancyFx 视图文件夹约定在带有 Owin 的 Azure 下不起作用
NancyFx view folder convention not working under Azure with Owin
我在 NancyFx 中有一个非常简单的模块和视图设置,比如这个;
public class LoginModule : NancyModule
{
public LoginModule()
{
Get["/login"] = _ => View["login", null];
}
}
此页面的视图位于 project\views\login\login.cshtml.
我已经配置了自定义视图约定来尝试解决问题,例如
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));
我正在使用 Owin(带有 ASP.NET 托管包的 Nancy 和 Microsoft 包)来管理我的网络 api 层。
该应用程序在本地测试时工作正常,但在部署到 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
请注意,它记录了我的视图的确切文件夹结构,但由于某种原因,找不到视图文件。
注意到支持的视图文件,所以选择了 Razor 包。
如果我将视图文件移动到 \views 文件夹中,一切正常,但如果可以的话,我想在逻辑上分隔文件。
项目与引用 Project.WebApi 的 Project.Web 项目分开(定义 Nancy 引导程序的 Owin 项目)。
为了回应另一个 post here,我将 Owin 处理程序添加到 Project.Web web.config 文件中。
<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>
但是没有成功。
问题只是 HTML 文件 .cshtml
需要将文件属性中的构建操作从 None
更改为 Content
已发布。
按记录工作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.
我在 NancyFx 中有一个非常简单的模块和视图设置,比如这个;
public class LoginModule : NancyModule
{
public LoginModule()
{
Get["/login"] = _ => View["login", null];
}
}
此页面的视图位于 project\views\login\login.cshtml.
我已经配置了自定义视图约定来尝试解决问题,例如
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));
我正在使用 Owin(带有 ASP.NET 托管包的 Nancy 和 Microsoft 包)来管理我的网络 api 层。
该应用程序在本地测试时工作正常,但在部署到 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
请注意,它记录了我的视图的确切文件夹结构,但由于某种原因,找不到视图文件。 注意到支持的视图文件,所以选择了 Razor 包。
如果我将视图文件移动到 \views 文件夹中,一切正常,但如果可以的话,我想在逻辑上分隔文件。
项目与引用 Project.WebApi 的 Project.Web 项目分开(定义 Nancy 引导程序的 Owin 项目)。
为了回应另一个 post here,我将 Owin 处理程序添加到 Project.Web web.config 文件中。
<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>
但是没有成功。
问题只是 HTML 文件 .cshtml
需要将文件属性中的构建操作从 None
更改为 Content
已发布。
按记录工作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.