dotnet / systemweb-adapters

MIT License
336 stars 59 forks source link

Ask About System.Web.Hosting.HostingEnvironment #368

Closed Clounea closed 1 year ago

Clounea commented 1 year ago

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

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)
  2. Get User from context when it is hosted

    if (System.Web.Hosting.HostingEnvironment.IsHosted)
    {
    HttpContext ctx= HttpContext.Current;
    if (ctx!= null)
    {
        return ctx.User;
    }
    }
  3. Use SiteName to find objects of a site

    var siteName= System.Web.Hosting.HostingEnvironment.SiteName;
    var targetObject = Database.Objects.Where(o =>o.SiteName == siteName)
  4. If the physicalpath (filepath) does not exist, return

    if (File.Exists(HostingEnvironment.MapPath("/targetPage.aspx")))
    return;
joperezr commented 1 year ago

[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.

twsouthwick commented 1 year ago

This relies (at least to get the information automatically) on: https://github.com/dotnet/aspnetcore/issues/43632

AvremelM commented 9 months ago

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.

twsouthwick commented 9 months ago

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