2017-07-06 45 views
0

我有一個南希項目,它服務於靜態內容,位於/my/web/root/。我創建了一個IRootPathProvider將webroot設置爲/my/web/root/,但是當我添加規則StaticContentConventionBuilder.AddDirectory("/", "/")時,「它不起作用」:服務器沒有響應。南希:服務於web根目錄中的靜態內容

我也可以將根路徑設置爲/my/web/,然後將規則路徑設置爲/root,但這非常醜陋,聽起來像是bug的來源。

有沒有辦法以一種整潔的方式解決這個問題?

回答

1

當我想在我的web應用程序的根目錄中提供靜態內容時,我按照以下方式配置Nancy。

public class CustomBoostrapper : DefaultNancyBootstrapper 
{ 
    protected override void ConfigureConventions(NancyConventions conventions) 
    { 
     base.ConfigureConventions(conventions); 

     conventions.StaticContentsConventions.Add(
      StaticContentConventionBuilder.AddDirectory("/", @"_Root") 
     ); 
    } 
} 

這將提供靜態內容從溶液中_root文件夾,但它會出現在應用程序的根。

例如

本地主機:3579 /的text.txt

應用程序,目錄服務\ _ROOT \的text.txt