簡體   English   中英

南希:從“/”提供靜態內容(例如index.html)?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM