dotnet/systemweb-adapters

Ask About System.Web.Hosting.HostingEnvironment

Clounea opened this issue · 4 comments

Summary

There are some APIs of HostingEnvironment missing in .NetCore. I want to ask if there are equivalents and if there is plan to add them to adapter.

Motivation and goals

We need migrate code (an API in Sharepoint) to ASP.NetCore and we find that the APIs are not supported by ASP.NetCore. These APIs seem not supported by IHostEnvironment.

In scope

  • System.Web.Hosting.HostingEnvironment.ApplicationID
  • System.Web.Hosting.HostingEnvironment.IsHosted
  • System.Web.Hosting.HostingEnvironment.SiteName
  • System.Web.Hosting.HostingEnvironment.MapPath

Examples

  1. Use applicationId to find objects of the application
var appId = System.Web.Hosting.HostingEnvironment.ApplicationID;
var targetObject = Database.Objects.First(o =>o.Id == appId)
  1. Get User from context when it is hosted
if (System.Web.Hosting.HostingEnvironment.IsHosted)
{
    HttpContext ctx= HttpContext.Current;
    if (ctx!= null)
    {
        return ctx.User;
    }
}
  1. Use SiteName to find objects of a site
var siteName= System.Web.Hosting.HostingEnvironment.SiteName;
var targetObject = Database.Objects.Where(o =>o.SiteName == siteName)
  1. If the physicalpath (filepath) does not exist, return
if (File.Exists(HostingEnvironment.MapPath("/targetPage.aspx")))
    return;

[Triage]: Some of the APIs proposed here might be harder to add as they require some runtime changes. We may want to split this issue into two in order to make some progress on the ones that don't. @twsouthwick will look into this.

This relies (at least to get the information automatically) on: dotnet/aspnetcore#43632

Was System.Web.Hosting.HostingEnvironment.MapPath not added as part of this?

It doesn't seem to be in the 1.3.0 release, that I can see.

@AvremelM you're right - MapPath did not get added here. Feel free to create a new issue and we're happy to take PRs