[英]Nancy response not returning proper MIME Type for index.html including
[英]Nancy: Serving static content (e.g. index.html) from “/”?
我正在尝试使用Nancy制作单页Web应用程序。 因此,我希望我的根URL提供一个普通的.html文件,没有任何视图逻辑或任何东西。
我试过了
Get["/"] = parameters => Response.AsHtml("content/index.html")
但是没有AsHtml
。
我试过一个自定义引导程序
conventions.StaticContentsConventions.Add(
StaticContentConventionBuilder.AddFile("/", @"content/index.html")
);
但显然它认为“/”不是文件 - 南希给我一个目录列表在http://localhost:<port>/
而不是。
我该怎么办? 这应该不是这么难,对吧?
PS。 任何方式关闭该目录列表? 感觉不安全。
添加默认情况下为index.html
提供服务的模块:
public IndexModule() : base("")
{
Get[@"/"] = parameters =>
{
return Response.AsFile("Content/index.html", "text/html");
};
}
然后使用引导程序中的约定为其余文件提供服务:
protected override void ConfigureConventions(NancyConventions nancyConventions)
{
nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/", "Content"));
base.ConfigureConventions(nancyConventions);
}
只需将它放在您的视图文件夹中即可:
Get["/"] = _ => View["index"];
目录列表与Nancy无关,无论您正在使用的托管是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.