Roboneter
Roboneter

Reputation: 897

AppDomainAppId in .NET Core?

When I get AppDomainAppId in .NET, I get a path like /LM/W3C/<site id>/<servicename>, how can I get the exact same path in an .NET Core service?

I tried the suggestion from HttpRuntime.AppDomainAppPath equivalent in ASP.NET Core but I got my install path like C:/path/to/app and not a path as described above.

How can I get the path described above or how can I specifically get the <site id> part? I can get the <servicename> from HostingEnvironment.ApplicationName but not the <site id> that I need.

Upvotes: 1

Views: 2091

Answers (2)

Shazwazza
Shazwazza

Reputation: 811

This sounds like it should work:

DataProtectionUtilityExtensions.GetApplicationUniqueIdentifier(IServiceProvider)

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.dataprotection.dataprotectionutilityextensions.getapplicationuniqueidentifier?view=aspnetcore-5.0

The returned identifier should be stable for repeated runs of this same application on this machine. Additionally, the identifier is only unique within the scope of a single machine, e.g., two different applications on two different machines may return the same value.

This API is explicitly hidden for some reason. Under the hood it uses IApplicationDiscriminator which is also explicitly hidden and says it shouldn't be used publicly :) https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.dataprotection.infrastructure.iapplicationdiscriminator?view=aspnetcore-5.0

The implementation is just based on the host environment ContentRootPath but perhaps there are other implementations when running on IIS, etc... which would return the same value as the old AppDomainAppId.

Upvotes: 0

SandRock
SandRock

Reputation: 5573

AppDomain is not included in dotnet core. Look at Replacing AppDomain in .Net Core for migration tips.

The path you get with .NET looks specific to the AppDomain implementation of ASP.NET. So I think you will not be able to get it with DNC.


In System.Web/HttpRuntime.cs/Init, we can see _appDomainAppId = GetAppDomainString(".appId");

GetAppDomainString(string key) calls Thread.GetDomain().GetData(key);. The GetDomain method is directly related to AppDomains. Those do not exist any more in DNC.

Upvotes: 1

Related Questions