May 5, 2022

IWebHostEnvironment MapPath Extension

Brings MapPath() to .NET Core

public static class IWebHostEnvironmentExtender
{
  public static string MapPath(
    this IWebHostEnvironment self, string path)
  {
    var res = path;
    var ix = path.IndexOf('~');
    if (ix == 0)
    {
      res = path.Replace("~", self.WebRootPath);
    }
    return res;
  }
}

No comments: