简体   繁体   中英

Nancy: serve static content in web root

I have a nancy project which is to serve static content, located in /my/web/root/ . I created a IRootPathProvider to set the webroot to /my/web/root/ , but when I add the rule StaticContentConventionBuilder.AddDirectory("/", "/") , "it does not work": the server does not respond.

I can also set the root path to /my/web/ and then set the rule path to /root , but that is very ugly, and sounds like a source for bugs.

Is there a way to solve this in a neat way?

When I want to serve static content at the root of my web app I configure Nancy the following way.

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

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

This will serve static content from a _Root folder in the solution but it will appear as at the root of the application.

eg

localhost:3579/text.txt

served from

app-dir\\_Root\\text.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM