Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nancy: is there a Server.MapPath("~/") equivalent?

I can't seem to find an equivalent in Nancy for System.Web.HttpContext.Current.Server.MapPath() in the Nancy framework.

I just want to load a textfile relative to the application service.

I see this in the assembly

using Nancy;
using System;

namespace Nancy.Hosting.Self
{
    public class FileSystemRootPathProvider : IRootPathProvider, IHideObjectMembers
    {
        public FileSystemRootPathProvider();

        public string GetRootPath();
    }
}

I'm not sure how to use.

update: I just figured out anything I need to load can just be read/written from the bin/relase/ directory. Is that the assumed way to do it in a Nancy Self Hosting environment? I guess that would make sense.

like image 737
FlavorScape Avatar asked Feb 11 '13 04:02

FlavorScape


People also ask

What is the mappath method?

As you most likely already know, the Server.MapPath method is a typical approach that we could use since classic ASP and ASP.NET Web Forms and MVC versions up to and including 5. Here's a typical way to use it:

What is mappath in Salesforce?

The MapPath method is used to define a relative virtual path for a physical directory on the server. Note: This method cannot be used in Session.OnEnd and Application.OnEnd. path: It stores a string value that defines the relative or virtual path to map to a physical directory.

Where does mappath return a file?

NOTE: The original .NET Framework Server.MapPath worked slightly differently returning d:\website\file.txt when called from with a path = "\file.txt", this returns just "file.txt". Just remove the initial "", to get similar results. Hope that helps Where does the env variable come from?

Where is the env variable equivalent in ASP NET Core 6?

@RolandWales, if you're using ASP.NET Core 6 with the new hosting model (without Startup.cs file), your env variable equivalent (originally a parameter of the Configure method in the Startup.cs class) is the builder.Environment property (in the Program.cs file).


1 Answers

You can take a dependency on IRootPathProvider and use that to call GetRootPath() that will give you the root of your application and you can add from there (I would recommend using Path.Combine)

like image 120
TheCodeJunkie Avatar answered Sep 28 '22 03:09

TheCodeJunkie