diff --git a/Microsoft.AspNetCore.SystemWebAdapters.sln b/Microsoft.AspNetCore.SystemWebAdapters.sln index d0618d83ae..c50328566f 100644 --- a/Microsoft.AspNetCore.SystemWebAdapters.sln +++ b/Microsoft.AspNetCore.SystemWebAdapters.sln @@ -72,12 +72,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.System EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests", "test\Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests\Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests.csproj", "{DFA4172D-7457-A613-E1D1-637955249FDF}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ServiceDefaults", "ServiceDefaults", "{F378E8D3-D932-4AA6-9463-136795A4ED37}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.ServiceDefaults.Core", "samples\ServiceDefaults\Samples.ServiceDefaults.Core\Samples.ServiceDefaults.Core.csproj", "{6067D2D5-9DA1-3491-1D33-4021B90800B9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.ServiceDefaults.Framework", "samples\ServiceDefaults\Samples.ServiceDefaults.Framework\Samples.ServiceDefaults.Framework.csproj", "{A97ECCC8-9E54-87FF-0F0A-D2A630B173E6}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineKeyAppHost", "samples\MachineKey\MachineKeyAppHost\MachineKeyAppHost.csproj", "{4FDC313D-1CF6-B330-3340-D3A2A4B729CE}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModulesAppHost", "samples\Modules\ModulesAppHost\ModulesAppHost.csproj", "{732062E0-EDD3-3CFC-1BA1-A10FA40D2622}" @@ -116,6 +110,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AuthWindows", "AuthWindows" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthWindowsCore", "samples\AuthWindows\AuthWindowsCore\AuthWindowsCore.csproj", "{64B09008-C9CB-BAEC-2AE1-616E6BE9880B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.ServiceDefaults", "samples\ServiceDefaults\Samples.ServiceDefaults.csproj", "{D08809BC-D4C3-F7C8-1C00-151CA8C6E504}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -186,14 +182,6 @@ Global {DFA4172D-7457-A613-E1D1-637955249FDF}.Debug|Any CPU.Build.0 = Debug|Any CPU {DFA4172D-7457-A613-E1D1-637955249FDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFA4172D-7457-A613-E1D1-637955249FDF}.Release|Any CPU.Build.0 = Release|Any CPU - {6067D2D5-9DA1-3491-1D33-4021B90800B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6067D2D5-9DA1-3491-1D33-4021B90800B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6067D2D5-9DA1-3491-1D33-4021B90800B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6067D2D5-9DA1-3491-1D33-4021B90800B9}.Release|Any CPU.Build.0 = Release|Any CPU - {A97ECCC8-9E54-87FF-0F0A-D2A630B173E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A97ECCC8-9E54-87FF-0F0A-D2A630B173E6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A97ECCC8-9E54-87FF-0F0A-D2A630B173E6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A97ECCC8-9E54-87FF-0F0A-D2A630B173E6}.Release|Any CPU.Build.0 = Release|Any CPU {4FDC313D-1CF6-B330-3340-D3A2A4B729CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4FDC313D-1CF6-B330-3340-D3A2A4B729CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FDC313D-1CF6-B330-3340-D3A2A4B729CE}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -254,6 +242,10 @@ Global {64B09008-C9CB-BAEC-2AE1-616E6BE9880B}.Debug|Any CPU.Build.0 = Debug|Any CPU {64B09008-C9CB-BAEC-2AE1-616E6BE9880B}.Release|Any CPU.ActiveCfg = Release|Any CPU {64B09008-C9CB-BAEC-2AE1-616E6BE9880B}.Release|Any CPU.Build.0 = Release|Any CPU + {D08809BC-D4C3-F7C8-1C00-151CA8C6E504}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D08809BC-D4C3-F7C8-1C00-151CA8C6E504}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D08809BC-D4C3-F7C8-1C00-151CA8C6E504}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D08809BC-D4C3-F7C8-1C00-151CA8C6E504}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -278,9 +270,6 @@ Global {17055F45-E79A-41EF-825E-0B2211433729} = {A1BDA50C-D70B-416C-97F1-74B0649797C5} {E4D9A131-DC4E-403F-A10F-65F5E5E42475} = {A1BDA50C-D70B-416C-97F1-74B0649797C5} {DFA4172D-7457-A613-E1D1-637955249FDF} = {A1BDA50C-D70B-416C-97F1-74B0649797C5} - {F378E8D3-D932-4AA6-9463-136795A4ED37} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7} - {6067D2D5-9DA1-3491-1D33-4021B90800B9} = {F378E8D3-D932-4AA6-9463-136795A4ED37} - {A97ECCC8-9E54-87FF-0F0A-D2A630B173E6} = {F378E8D3-D932-4AA6-9463-136795A4ED37} {4FDC313D-1CF6-B330-3340-D3A2A4B729CE} = {03E4CEAB-D845-402A-9311-F7390B24BA2A} {732062E0-EDD3-3CFC-1BA1-A10FA40D2622} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C} {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7} @@ -300,6 +289,7 @@ Global {6C3B0EEA-CDD2-D218-9767-4A5E923F295A} = {87516E0D-8F1C-4788-AEBD-65A98775CF8F} {AC29CA1D-A850-4C29-B27D-C23BAF3D664C} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7} {64B09008-C9CB-BAEC-2AE1-616E6BE9880B} = {AC29CA1D-A850-4C29-B27D-C23BAF3D664C} + {D08809BC-D4C3-F7C8-1C00-151CA8C6E504} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DABA3C65-9D74-4EB6-9B1C-730328710EAD} diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/AuthRemoteFormsAuthAppHost.csproj b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/AuthRemoteFormsAuthAppHost.csproj index 6bf5160c7e..108d000bbb 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/AuthRemoteFormsAuthAppHost.csproj +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/AuthRemoteFormsAuthAppHost.csproj @@ -4,7 +4,7 @@ Exe - net9.0-windows + net10.0-windows enable enable true diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs index f67576f2ad..581384ac47 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs @@ -5,11 +5,13 @@ var frameworkApp = builder.AddIISExpress("iis") .AddSiteProject("framework") .WithDefaultIISExpressEndpoints() + .WithOtlpExporter() .WithEnvironment("RemoteApp__ApiKey", remoteApiKey) .WithHttpHealthCheck(); var coreApp = builder.AddProject("core") .WithEnvironment("RemoteApp__ApiKey", remoteApiKey) + .WithReference(frameworkApp) .WithEnvironment("RemoteApp__Url", frameworkApp.GetEndpoint("https")) .WithHttpHealthCheck() .WaitFor(frameworkApp); diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Properties/launchSettings.json b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Properties/launchSettings.json +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/AuthRemoteFormsAuthCore.csproj b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/AuthRemoteFormsAuthCore.csproj index 6a1316390f..b619f5f112 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/AuthRemoteFormsAuthCore.csproj +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/AuthRemoteFormsAuthCore.csproj @@ -1,6 +1,6 @@ - net9.0 + net10.0 enable enable @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj index 89bfcaf96c..6867d46660 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj @@ -14,7 +14,7 @@ - + diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Global.asax.cs b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Global.asax.cs index 7bb71a845a..0d328c8e15 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Global.asax.cs +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Global.asax.cs @@ -4,21 +4,27 @@ using System.Web.Optimization; using System.Web.Routing; using Microsoft.AspNetCore.SystemWebAdapters; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; namespace FormsAuth { public class Global : HttpApplication { - void Application_Start(object sender, EventArgs e) + protected void Application_Start() { - SystemWebAdapterConfiguration.AddSystemWebAdapters(this) - .AddVirtualizedContentDirectories() - .AddProxySupport(options => options.UseForwardedHeaders = true) - .AddRemoteAppServer(options => - { - options.ApiKey = ConfigurationManager.AppSettings["RemoteApp__ApiKey"]; - }) - .AddAuthenticationServer(); + HttpApplicationHost.RegisterHost(builder => + { + builder.AddServiceDefaults(); + builder.RegisterWebObjectActivator(); + + builder.Services.AddSystemAdapters() + .AddVirtualizedContentDirectories() + .AddProxySupport(options => options.UseForwardedHeaders = true) + .AddRemoteAppServer(builder.Configuration.GetSection("RemoteApp").Bind) + .AddAuthenticationServer(); + }); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Web.config b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Web.config index 5da04cb32e..240b79041a 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Web.config +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Web.config @@ -46,57 +46,147 @@ - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/AuthRemoteIdentityAppHost.csproj b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/AuthRemoteIdentityAppHost.csproj index 8db72812ef..01420d59a7 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/AuthRemoteIdentityAppHost.csproj +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/AuthRemoteIdentityAppHost.csproj @@ -4,7 +4,7 @@ Exe - net9.0-windows + net10.0-windows enable enable true diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs index adc0df147b..6a450af997 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs @@ -1,3 +1,6 @@ +using System.Security.Policy; +using Microsoft.Extensions.Configuration; + var builder = DistributedApplication.CreateBuilder(args); var remoteApiKey = builder.AddParameter("apiKey", Guid.NewGuid().ToString(), secret: true); @@ -12,6 +15,7 @@ .WithDefaultIISExpressEndpoints() .WithEnvironment("RemoteApp__ApiKey", remoteApiKey) .WithReference(db, connectionName: "DefaultConnection") + .WithOtlpExporter() .WaitFor(db) .WithHttpHealthCheck(); diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Properties/launchSettings.json b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Properties/launchSettings.json +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/AuthRemoteIdentityCore.csproj b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/AuthRemoteIdentityCore.csproj index 6a1316390f..b619f5f112 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/AuthRemoteIdentityCore.csproj +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/AuthRemoteIdentityCore.csproj @@ -1,6 +1,6 @@ - net9.0 + net10.0 enable enable @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/AuthRemoteIdentityFramework.csproj b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/AuthRemoteIdentityFramework.csproj index f38757535b..9d85d5c501 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/AuthRemoteIdentityFramework.csproj +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/AuthRemoteIdentityFramework.csproj @@ -1,4 +1,4 @@ - + net481 @@ -10,11 +10,6 @@ - - - - - @@ -30,10 +25,10 @@ - + - + diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Global.asax.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Global.asax.cs index 08fabcc1b4..798c803ba8 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Global.asax.cs +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Global.asax.cs @@ -4,18 +4,27 @@ using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; namespace MvcApp { - public class MvcApplication : System.Web.HttpApplication + public class MvcApplication : HttpApplication { protected void Application_Start() { - SystemWebAdapterConfiguration.AddSystemWebAdapters(this) - .AddVirtualizedContentDirectories() - .AddProxySupport(options => options.UseForwardedHeaders = true) - .AddRemoteAppServer(options => options.ApiKey = ConfigurationManager.AppSettings["RemoteApp__ApiKey"]) - .AddAuthenticationServer(); + HttpApplicationHost.RegisterHost(builder => + { + builder.AddServiceDefaults(); + builder.RegisterWebObjectActivator(); + + builder.Services.AddSystemAdapters() + .AddVirtualizedContentDirectories() + .AddProxySupport(options => options.UseForwardedHeaders = true) + .AddRemoteAppServer(builder.Configuration.GetSection("RemoteApp").Bind) + .AddAuthenticationServer(); + }); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config index 535b0d88ae..7fe144ee87 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config @@ -69,38 +69,110 @@ - - + + - - + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + @@ -147,8 +219,14 @@ - - + + + + + + + + @@ -163,6 +241,12 @@ + + + + + + diff --git a/samples/AuthWindows/AuthWindowsCore/AuthWindowsCore.csproj b/samples/AuthWindows/AuthWindowsCore/AuthWindowsCore.csproj index 69f9a7a610..02cd8b348c 100644 --- a/samples/AuthWindows/AuthWindowsCore/AuthWindowsCore.csproj +++ b/samples/AuthWindows/AuthWindowsCore/AuthWindowsCore.csproj @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 08f044f9e3..9a8659ad18 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -2,6 +2,7 @@ + true false diff --git a/samples/Directory.Packages.props b/samples/Directory.Packages.props index 0c525b7eb2..1486540749 100644 --- a/samples/Directory.Packages.props +++ b/samples/Directory.Packages.props @@ -28,15 +28,16 @@ - - - - - - + + + + + + + - - + + @@ -47,14 +48,17 @@ - - - - - + + + + + + + + - + diff --git a/samples/MachineKey/MachineKeyAppHost/Program.cs b/samples/MachineKey/MachineKeyAppHost/Program.cs index 82a045f861..969eb80bb4 100644 --- a/samples/MachineKey/MachineKeyAppHost/Program.cs +++ b/samples/MachineKey/MachineKeyAppHost/Program.cs @@ -3,6 +3,7 @@ var frameworkApp = builder.AddIISExpress("iis") .AddSiteProject("framework") .WithDefaultIISExpressEndpoints() + .WithOtlpExporter() .WithHttpHealthCheck(); var coreApp = builder.AddProject("core") diff --git a/samples/MachineKey/MachineKeyAppHost/Properties/launchSettings.json b/samples/MachineKey/MachineKeyAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/MachineKey/MachineKeyAppHost/Properties/launchSettings.json +++ b/samples/MachineKey/MachineKeyAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/MachineKey/MachineKeyCore/MachineKeyCore.csproj b/samples/MachineKey/MachineKeyCore/MachineKeyCore.csproj index 77b351d1dd..16f4bfe65a 100644 --- a/samples/MachineKey/MachineKeyCore/MachineKeyCore.csproj +++ b/samples/MachineKey/MachineKeyCore/MachineKeyCore.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable @@ -9,6 +9,7 @@ + diff --git a/samples/MachineKey/MachineKeyFramework/MachineKeyFramework.csproj b/samples/MachineKey/MachineKeyFramework/MachineKeyFramework.csproj index 783085de36..1b6276f645 100644 --- a/samples/MachineKey/MachineKeyFramework/MachineKeyFramework.csproj +++ b/samples/MachineKey/MachineKeyFramework/MachineKeyFramework.csproj @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/samples/MachineKey/MachineKeyFramework/Web.config b/samples/MachineKey/MachineKeyFramework/Web.config index 318c803ac9..a0c770ec94 100644 --- a/samples/MachineKey/MachineKeyFramework/Web.config +++ b/samples/MachineKey/MachineKeyFramework/Web.config @@ -19,22 +19,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -50,4 +152,4 @@ - + \ No newline at end of file diff --git a/samples/Modules/ModulesAppHost/Program.cs b/samples/Modules/ModulesAppHost/Program.cs index b3b8cfd025..f56119a7a0 100644 --- a/samples/Modules/ModulesAppHost/Program.cs +++ b/samples/Modules/ModulesAppHost/Program.cs @@ -3,6 +3,7 @@ var frameworkApp = builder.AddIISExpress("iis") .AddSiteProject("framework") .WithDefaultIISExpressEndpoints() + .WithOtlpExporter() .WithHttpHealthCheck(); var coreApp = builder.AddProject("core") diff --git a/samples/Modules/ModulesAppHost/Properties/launchSettings.json b/samples/Modules/ModulesAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/Modules/ModulesAppHost/Properties/launchSettings.json +++ b/samples/Modules/ModulesAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/Modules/ModulesCore/ModulesCore.csproj b/samples/Modules/ModulesCore/ModulesCore.csproj index 2de8a5daac..d0630adc16 100644 --- a/samples/Modules/ModulesCore/ModulesCore.csproj +++ b/samples/Modules/ModulesCore/ModulesCore.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable @@ -9,6 +9,7 @@ + diff --git a/samples/Modules/ModulesFramework/ModulesFramework.csproj b/samples/Modules/ModulesFramework/ModulesFramework.csproj index 7bd55c1539..b7e2e86217 100644 --- a/samples/Modules/ModulesFramework/ModulesFramework.csproj +++ b/samples/Modules/ModulesFramework/ModulesFramework.csproj @@ -5,5 +5,6 @@ + diff --git a/samples/Modules/ModulesFramework/Web.config b/samples/Modules/ModulesFramework/Web.config index a5ac808b85..01e6bb3127 100644 --- a/samples/Modules/ModulesFramework/Web.config +++ b/samples/Modules/ModulesFramework/Web.config @@ -6,14 +6,142 @@ - + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Core/Extensions.cs b/samples/ServiceDefaults/Extensions.cs similarity index 87% rename from samples/ServiceDefaults/Samples.ServiceDefaults.Core/Extensions.cs rename to samples/ServiceDefaults/Extensions.cs index a47094f557..a732dc5698 100644 --- a/samples/ServiceDefaults/Samples.ServiceDefaults.Core/Extensions.cs +++ b/samples/ServiceDefaults/Extensions.cs @@ -1,13 +1,19 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; + +using System.Net.Http; +using Microsoft.AspNetCore.SystemWebAdapters; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.ServiceDiscovery; using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; +#if NET +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.ServiceDiscovery; +#endif + namespace Microsoft.Extensions.Hosting; // Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry. @@ -21,15 +27,19 @@ public static TBuilder AddServiceDefaults(this TBuilder builder) where builder.AddDefaultHealthChecks(); +#if NET builder.Services.AddServiceDiscovery(); +#endif builder.Services.ConfigureHttpClientDefaults(http => { // Turn on resilience by default http.AddStandardResilienceHandler(); +#if NET // Turn on service discovery by default http.AddServiceDiscovery(); +#endif }); // Uncomment the following to restrict the allowed schemes for service discovery. @@ -52,16 +62,25 @@ public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) w builder.Services.AddOpenTelemetry() .WithMetrics(metrics => { - metrics.AddAspNetCoreInstrumentation() + metrics +#if NET + .AddAspNetCoreInstrumentation() +#else + .AddAspNetInstrumentation() +#endif + .AddSqlClientInstrumentation() .AddHttpClientInstrumentation() .AddRuntimeInstrumentation(); }) .WithTracing(tracing => { tracing.AddSource(builder.Environment.ApplicationName) +#if NET .AddAspNetCoreInstrumentation() - // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) - //.AddGrpcClientInstrumentation() +#else + .AddAspNetInstrumentation() +#endif + .AddSqlClientInstrumentation() .AddHttpClientInstrumentation(); }); @@ -72,7 +91,8 @@ public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) w private static TBuilder AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder { - var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + var otlpEndpoint = builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]; + var useOtlpExporter = !string.IsNullOrWhiteSpace(otlpEndpoint); if (useOtlpExporter) { @@ -98,6 +118,7 @@ public static TBuilder AddDefaultHealthChecks(this TBuilder builder) w return builder; } +#if NET public static WebApplication MapDefaultEndpoints(this WebApplication app) { // Adding health checks endpoints to applications in non-development environments has security implications. @@ -116,4 +137,5 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app) return app; } +#endif } diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/ContentFileExtensions.cs b/samples/ServiceDefaults/Framework/ContentFileExtensions.cs similarity index 100% rename from samples/ServiceDefaults/Samples.ServiceDefaults.Framework/ContentFileExtensions.cs rename to samples/ServiceDefaults/Framework/ContentFileExtensions.cs diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/FileProviderVirtualPathProvider.cs b/samples/ServiceDefaults/Framework/FileProviderVirtualPathProvider.cs similarity index 100% rename from samples/ServiceDefaults/Samples.ServiceDefaults.Framework/FileProviderVirtualPathProvider.cs rename to samples/ServiceDefaults/Framework/FileProviderVirtualPathProvider.cs diff --git a/samples/ServiceDefaults/Framework/SamplesServiceDefaultsStartup.cs b/samples/ServiceDefaults/Framework/SamplesServiceDefaultsStartup.cs new file mode 100644 index 0000000000..844f1593c8 --- /dev/null +++ b/samples/ServiceDefaults/Framework/SamplesServiceDefaultsStartup.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Web; +using System.Web.Hosting; +using OpenTelemetry; +using OpenTelemetry.Instrumentation.AspNet; + +[assembly: PreApplicationStartMethod(typeof(SamplesServiceDefaultsStartup), nameof(SamplesServiceDefaultsStartup.Startup))] + +namespace System.Web; + +public static class SamplesServiceDefaultsStartup +{ + public static void Startup() + { + HttpApplication.RegisterModule(typeof(TelemetryHttpModule)); + } +} diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/StaticFileProviderHttpModule.cs b/samples/ServiceDefaults/Framework/StaticFileProviderHttpModule.cs similarity index 100% rename from samples/ServiceDefaults/Samples.ServiceDefaults.Framework/StaticFileProviderHttpModule.cs rename to samples/ServiceDefaults/Framework/StaticFileProviderHttpModule.cs diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Core/Samples.ServiceDefaults.Core.csproj b/samples/ServiceDefaults/Samples.ServiceDefaults.Core/Samples.ServiceDefaults.Core.csproj deleted file mode 100644 index c808e113c9..0000000000 --- a/samples/ServiceDefaults/Samples.ServiceDefaults.Core/Samples.ServiceDefaults.Core.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - net9.0 - enable - enable - true - - - - - - - - - - - - - - - - - - - diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/Samples.ServiceDefaults.Framework.csproj b/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/Samples.ServiceDefaults.Framework.csproj deleted file mode 100644 index 51e0a82f17..0000000000 --- a/samples/ServiceDefaults/Samples.ServiceDefaults.Framework/Samples.ServiceDefaults.Framework.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - net481 - enable - enable - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.csproj b/samples/ServiceDefaults/Samples.ServiceDefaults.csproj new file mode 100644 index 0000000000..0cad0e40eb --- /dev/null +++ b/samples/ServiceDefaults/Samples.ServiceDefaults.csproj @@ -0,0 +1,39 @@ + + + + net481;net9.0 + enable + enable + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/SessionRemote/SessionRemoteAppHost/Program.cs b/samples/SessionRemote/SessionRemoteAppHost/Program.cs index 6cbcfd7989..30de519a7c 100644 --- a/samples/SessionRemote/SessionRemoteAppHost/Program.cs +++ b/samples/SessionRemote/SessionRemoteAppHost/Program.cs @@ -5,6 +5,7 @@ var frameworkApp = builder.AddIISExpress("iis") .AddSiteProject("framework") .WithDefaultIISExpressEndpoints() + .WithOtlpExporter() .WithEnvironment("RemoteApp__ApiKey", remoteApiKey) .WithHttpHealthCheck(path: "/framework"); diff --git a/samples/SessionRemote/SessionRemoteAppHost/Properties/launchSettings.json b/samples/SessionRemote/SessionRemoteAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/SessionRemote/SessionRemoteAppHost/Properties/launchSettings.json +++ b/samples/SessionRemote/SessionRemoteAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/SessionRemote/SessionRemoteAppHost/SessionRemoteAppHost.csproj b/samples/SessionRemote/SessionRemoteAppHost/SessionRemoteAppHost.csproj index 6278c95e93..1167927a9b 100644 --- a/samples/SessionRemote/SessionRemoteAppHost/SessionRemoteAppHost.csproj +++ b/samples/SessionRemote/SessionRemoteAppHost/SessionRemoteAppHost.csproj @@ -4,7 +4,7 @@ Exe - net9.0-windows + net10.0-windows enable enable true diff --git a/samples/SessionRemote/SessionRemoteCore/SessionRemoteCore.csproj b/samples/SessionRemote/SessionRemoteCore/SessionRemoteCore.csproj index 6a1316390f..154c818c7c 100644 --- a/samples/SessionRemote/SessionRemoteCore/SessionRemoteCore.csproj +++ b/samples/SessionRemote/SessionRemoteCore/SessionRemoteCore.csproj @@ -1,4 +1,4 @@ - + net9.0 enable @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/samples/SessionRemote/SessionRemoteFramework/Global.asax.cs b/samples/SessionRemote/SessionRemoteFramework/Global.asax.cs index 2911baae17..d5c65e271c 100644 --- a/samples/SessionRemote/SessionRemoteFramework/Global.asax.cs +++ b/samples/SessionRemote/SessionRemoteFramework/Global.asax.cs @@ -2,6 +2,10 @@ using System.Configuration; using System.Web; using System.Web.Routing; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace RemoteSessionFramework { @@ -9,19 +13,21 @@ public class SessionApplication : HttpApplication { protected void Application_Start() { - SystemWebAdapterConfiguration.AddSystemWebAdapters(this) - .AddProxySupport(options => options.UseForwardedHeaders = true) - .AddSessionSerializer(options => - { - }) - .AddJsonSessionSerializer(options => - { - options.RegisterKey("CoreCount"); - }) - .AddRemoteAppServer(options => options.ApiKey = ConfigurationManager.AppSettings["RemoteApp__ApiKey"]) - .AddSessionServer(options => - { - }); + HttpApplicationHost.RegisterHost(builder => + { + builder.AddServiceDefaults(); + builder.Services.AddSystemAdapters() + .AddProxySupport(options => options.UseForwardedHeaders = true) + .AddSessionSerializer(options => + { + }) + .AddJsonSessionSerializer(options => + { + options.RegisterKey("CoreCount"); + }) + .AddRemoteAppServer(builder.Configuration.GetSection("RemoteApp").Bind) + .AddSessionServer(); + }); } protected void Application_PostAcquireRequestState(object sender, EventArgs e) diff --git a/samples/SessionRemote/SessionRemoteFramework/SessionRemoteFramework.csproj b/samples/SessionRemote/SessionRemoteFramework/SessionRemoteFramework.csproj index df78a7d969..a815a33aa9 100644 --- a/samples/SessionRemote/SessionRemoteFramework/SessionRemoteFramework.csproj +++ b/samples/SessionRemote/SessionRemoteFramework/SessionRemoteFramework.csproj @@ -1,4 +1,4 @@ - + net481 @@ -13,5 +13,6 @@ + diff --git a/samples/SessionRemote/SessionRemoteFramework/Web.config b/samples/SessionRemote/SessionRemoteFramework/Web.config index 1ca7507ce1..8907b0d266 100644 --- a/samples/SessionRemote/SessionRemoteFramework/Web.config +++ b/samples/SessionRemote/SessionRemoteFramework/Web.config @@ -33,39 +33,129 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs index 5004a04546..e362c7e6fd 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs +++ b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs @@ -5,6 +5,7 @@ var frameworkApp = builder.AddIISExpress("iis") .AddSiteProject("framework") .WithDefaultIISExpressEndpoints() + .WithOtlpExporter() .WithEnvironment("RemoteApp__ApiKey", remoteApiKey) .WithHttpHealthCheck(); diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Properties/launchSettings.json b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Properties/launchSettings.json index fc25ecd39f..90eb3c954c 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Properties/launchSettings.json +++ b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Properties/launchSettings.json @@ -9,7 +9,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:21002", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" } }, @@ -21,7 +21,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", + "ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:19075", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" } } diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorCore/WebFormsToBlazorCore.csproj b/samples/WebFormsToBlazor/WebFormsToBlazorCore/WebFormsToBlazorCore.csproj index 23fd3ecec3..f883bb8a80 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorCore/WebFormsToBlazorCore.csproj +++ b/samples/WebFormsToBlazor/WebFormsToBlazorCore/WebFormsToBlazorCore.csproj @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Global.asax.cs b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Global.asax.cs index 0edb8b8097..bbcddbd34a 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Global.asax.cs +++ b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Global.asax.cs @@ -3,25 +3,30 @@ using System.Web; using System.Web.Optimization; using System.Web.Routing; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; namespace WebFormsFramework { public class Global : HttpApplication { - void Application_Start(object sender, EventArgs e) + protected void Application_Start() { - SystemWebAdapterConfiguration.AddSystemWebAdapters(this) - .AddVirtualizedContentDirectories() - .AddProxySupport(options => options.UseForwardedHeaders = true) - .AddJsonSessionSerializer(options => - { - options.RegisterKey("test-value"); - }) - .AddRemoteAppServer(options => - { - options.ApiKey = ConfigurationManager.AppSettings["RemoteApp__ApiKey"]; - }) - .AddSessionServer(); + HttpApplicationHost.RegisterHost(builder => + { + builder.AddServiceDefaults(); + + builder.Services.AddSystemAdapters() + .AddVirtualizedContentDirectories() + .AddProxySupport(options => options.UseForwardedHeaders = true) + .AddJsonSessionSerializer(options => + { + options.RegisterKey("test-value"); + }) + .AddRemoteAppServer(builder.Configuration.GetSection("RemoteApp").Bind) + .AddSessionServer(); + }); // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Web.config b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Web.config index a59133324f..237d1ed808 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Web.config +++ b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/Web.config @@ -49,57 +49,147 @@ - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/WebFormsToBlazorFramework.csproj b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/WebFormsToBlazorFramework.csproj index 69e7f212ea..1226ccd518 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorFramework/WebFormsToBlazorFramework.csproj +++ b/samples/WebFormsToBlazor/WebFormsToBlazorFramework/WebFormsToBlazorFramework.csproj @@ -16,9 +16,9 @@ - + - + \ No newline at end of file diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index b68e23b931..8641326dcb 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -7,6 +7,7 @@ + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/ConfigurationManagerConfigExtensions.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/ConfigurationManagerConfigExtensions.cs new file mode 100644 index 0000000000..361daab90f --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/ConfigurationManagerConfigExtensions.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Memory; + +namespace Microsoft.AspNetCore.SystemWebAdapters.Hosting; + +internal static class ConfigurationManagerConfigExtensions +{ + public static IConfigurationBuilder AddConfigurationManager(this IConfigurationBuilder builder) + { + if (builder is null) + { + throw new ArgumentNullException(nameof(builder)); + } + + var initialData = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (var connStr in System.Configuration.ConfigurationManager.ConnectionStrings.OfType()) + { + if (connStr is { Key: string key, Value: string value }) + { + initialData.Add("ConnectionStrings:" + key, value); + } + } + + foreach (var appSetting in System.Configuration.ConfigurationManager.AppSettings.OfType()) + { + if (appSetting is { Key: string key, Value: string value }) + { + initialData.Add(key, value); + } + } + + builder.AddInMemoryCollection(initialData); + + return builder; + } +} + + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHost.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHost.cs new file mode 100644 index 0000000000..54301045d0 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHost.cs @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; +using System.Web.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Microsoft.AspNetCore.SystemWebAdapters.Hosting; + +public sealed class HttpApplicationHost : IHost +{ + private static HttpApplicationHost? _current; + + private readonly IHost _host; + + public static HttpApplicationHost Current => _current ?? throw new InvalidOperationException("Host is not initialized"); + + internal HttpApplicationHost(IHost host) + { + if (_current is { }) + { + throw new InvalidOperationException("HttpApplicationHost has already been initialized"); + } + + _host = host; + _current = this; + } + + public static HttpApplicationHostBuilder CreateBuilder() + { + var config = new ConfigurationManager(); + + config.AddConfigurationManager(); + + var builder = new HostApplicationBuilder(new HostApplicationBuilderSettings() + { + Configuration = config, + ApplicationName = HostingEnvironment.SiteName, + ContentRootPath = HostingEnvironment.ApplicationPhysicalPath, + EnvironmentName = HostingEnvironment.IsDevelopmentEnvironment || IsIISExpress() ? Environments.Development : Environments.Production + }); + + builder.Services.AddSingleton(); + + return new(builder); + + static bool IsIISExpress() + { + using var currentProcess = Process.GetCurrentProcess(); + + return string.Equals(currentProcess.ProcessName, "iisexpress", StringComparison.Ordinal); + } + } + + public static void RegisterHost(Action configure) + { + if (configure is null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var builder = CreateBuilder(); + configure(builder); + builder.BuildAndRunInBackground(); + } + + public IServiceProvider Services => _host.Services; + + public Task StartAsync(CancellationToken cancellationToken) + => _host.StartAsync(cancellationToken); + + public Task StopAsync(CancellationToken cancellationToken) + => _host.StopAsync(cancellationToken); + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "Disposed of by IIS lifetime management and this is a sealed class")] + void IDisposable.Dispose() + { + _host.Dispose(); + _current = null; + } +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHostBuilder.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHostBuilder.cs new file mode 100644 index 0000000000..033c6ef454 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationHostBuilder.cs @@ -0,0 +1,50 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Web.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.Metrics; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.SystemWebAdapters.Hosting; + +public sealed class HttpApplicationHostBuilder : IHostApplicationBuilder +{ + private readonly HostApplicationBuilder _other; + + internal HttpApplicationHostBuilder(HostApplicationBuilder other) + { + _other = other; + } + + IDictionary IHostApplicationBuilder.Properties => ((IHostApplicationBuilder)_other).Properties; + + public IConfigurationManager Configuration => _other.Configuration; + + public IHostEnvironment Environment => _other.Environment; + + public ILoggingBuilder Logging => _other.Logging; + + public IMetricsBuilder Metrics => _other.Metrics; + + public IServiceCollection Services => _other.Services; + + public void ConfigureContainer(IServiceProviderFactory factory, Action? configure = null) where TContainerBuilder : notnull + { + _other.ConfigureContainer(factory, configure); + } + + internal HttpApplicationHost Build() => new(_other.Build()); + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed in the RunAsync method")] + internal void BuildAndRunInBackground() + { + var host = Build(); + + HostingEnvironment.QueueBackgroundWorkItem(host.RunAsync); + } +} + + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationLifetime.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationLifetime.cs new file mode 100644 index 0000000000..dc20190c86 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Hosting/HttpApplicationLifetime.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Web; +using System.Web.Hosting; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.SystemWebAdapters.Hosting; + +internal sealed partial class HttpApplicationLifetime : IHostLifetime, IRegisteredObject, IDisposable +{ + private readonly IHostApplicationLifetime _applicationLifetime; + private readonly ILogger _logger; + private readonly IHostEnvironment _environment; + + [LoggerMessage(LogLevel.Information, "Shutting down application for {Reason}")] + private partial void LogShutdown(ApplicationShutdownReason reason); + + [LoggerMessage(LogLevel.Information, "Application started. Hosting environment: {EnvName}; Content root path: {ContentRoot}")] + private partial void LogStarted(string envName, string contentRoot); + + [LoggerMessage(LogLevel.Information, "Application is shutting down...")] + private partial void LogStopping(); + + [LoggerMessage(LogLevel.Information, "Application has stopped.")] + private partial void LogStopped(); + + public HttpApplicationLifetime( + IHostEnvironment environment, + IHostApplicationLifetime applicationLifetime, + ILogger logger + ) + { + _applicationLifetime = applicationLifetime; + _logger = logger; + _environment = environment; + + HostingEnvironment.RegisterObject(this); + } + + void IRegisteredObject.Stop(bool immediate) + { + HostingEnvironment.UnregisterObject(this); + HostingEnvironment.QueueBackgroundWorkItem(_ => _applicationLifetime.StopApplication()); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + HostingEnvironment.UnregisterObject(this); + LogShutdown(HostingEnvironment.ShutdownReason); + + return Task.CompletedTask; + } + + Task IHostLifetime.WaitForStartAsync(CancellationToken cancellationToken) + { + _applicationLifetime.ApplicationStarted.Register(() => + { + LogStarted(_environment.EnvironmentName, _environment.ContentRootPath); + }); + _applicationLifetime.ApplicationStopping.Register(() => + { + LogStopping(); + }); + _applicationLifetime.ApplicationStopped.Register(() => + { + LogStopped(); + + HostingEnvironment.InitiateShutdown(); + }); + + return Task.CompletedTask; + } + + public void Dispose() + { + HostingEnvironment.UnregisterObject(this); + } +} + + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj index 6b5f7bf3c6..b292e34331 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj @@ -17,6 +17,7 @@ + @@ -25,9 +26,7 @@ - - - + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterConfiguration.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterConfiguration.cs index 0d4a7dc3ce..ad8ae65a67 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterConfiguration.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterConfiguration.cs @@ -2,9 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Web; using Microsoft.AspNetCore.SystemWebAdapters; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace System.Web; @@ -12,6 +13,7 @@ public static class SystemWebAdapterConfiguration { private const string Key = "system-web-adapter"; + [Obsolete("Prefer using HostedHttpApplication instead")] public static ISystemWebAdapterBuilder AddSystemWebAdapters(this HttpApplication application) { if (application is null) @@ -24,11 +26,9 @@ public static ISystemWebAdapterBuilder AddSystemWebAdapters(this HttpApplication { if (application.Application[Key] is null) { - var services = new ServiceCollection(); + var builder = HttpApplicationHost.CreateBuilder(); - services.AddLogging(); - - application.Application[Key] = new SystemWebAdapterBuilder(services); + application.Application[Key] = builder; // If a service provider has been created, ensure it's disposed at // application shutdown. @@ -41,9 +41,9 @@ public static ISystemWebAdapterBuilder AddSystemWebAdapters(this HttpApplication }; } - if (application.Application[Key] is ISystemWebAdapterBuilder builder) + if (application.Application[Key] is HttpApplicationHostBuilder existing) { - return builder; + return existing.Services.AddSystemAdapters(); } else { @@ -75,29 +75,36 @@ public static ISystemWebAdapterBuilder AddProxySupport(this ISystemWebAdapterBui return builder; } - internal static IServiceProvider? GetServiceProvider(this HttpApplicationState state) + [Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Lifetime managed with IIS lifecycle")] + internal static void EnsureSystemWebAdapterBuilderBuilt(this HttpApplicationState state) { - if (state[Key] is ISystemWebAdapterBuilder) + if (state[Key] is HttpApplicationHostBuilder) { - Build(state); + if (Build(state) is { } builder) + { + builder.BuildAndRunInBackground(); + } } - - return state[Key] as IServiceProvider; } - private static void Build(HttpApplicationState state) + private static HttpApplicationHostBuilder? Build(HttpApplicationState state) { state.Lock(); try { - if (state[Key] is ISystemWebAdapterBuilder builder) + if (state[Key] is HttpApplicationHostBuilder builder) { - state[Key] = builder.Services.BuildServiceProvider(); + // Set it as a random object so it can be tracked that it was already built + state[Key] = new object(); + + return builder; } } finally { state.UnLock(); } + + return null; } } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterExtensions.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterExtensions.cs new file mode 100644 index 0000000000..2c9c416517 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterExtensions.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Web; +using Microsoft.AspNetCore.SystemWebAdapters; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace System.Web; + +public static partial class SystemWebAdapterExtensions +{ + public static HttpApplicationHostBuilder RegisterWebObjectActivator(this HttpApplicationHostBuilder builder) + { + if (builder is null) + { + throw new ArgumentNullException(nameof(builder)); + } + + builder.Services.AddHostedService(); + + return builder; + } + + public static ISystemWebAdapterBuilder AddSystemAdapters(this IServiceCollection services) + => new SystemWebAdapterBuilder(services); + + private sealed partial class WebObjectActivatorHostServices : IServiceProvider, IHostedService + { + private const string ErrorMessage = "WebObjectActivator is already set and will not be overridden"; + + private readonly IServiceProvider _services; + + public WebObjectActivatorHostServices(IServiceProvider services) + { + if (HttpRuntime.WebObjectActivator is { }) + { + throw new InvalidOperationException("HttpRuntime.WebObjectActivator is already configured"); + } + + _services = services; + } + + public object? GetService(Type serviceType) + { + if (serviceType == typeof(IServiceProvider)) + { + return _services; + } + else if (serviceType == typeof(IKeyedServiceProvider) && _services is IKeyedServiceProvider keyed) + { + return keyed; + } + else if (_services.GetService(serviceType) is { } known) + { + return known; + } + else if (serviceType.IsAbstract) + { + return null; + } + + return CreateNonPublicInstance(serviceType); + + // The implementation of dependency injection in System.Web expects to be able to create instances + // of non-public and unregistered types. + static object CreateNonPublicInstance(Type serviceType) => Activator.CreateInstance( + serviceType, + BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance, + null, + null, + null); + } + + Task IHostedService.StartAsync(CancellationToken cancellationToken) + { + if (HttpRuntime.WebObjectActivator is { }) + { + LogAlreadySet(_services.GetRequiredService>()); + throw new InvalidOperationException(ErrorMessage); + } + + HttpRuntime.WebObjectActivator = this; + return Task.CompletedTask; + } + + Task IHostedService.StopAsync(CancellationToken cancellationToken) + { + HttpRuntime.WebObjectActivator = null; + return Task.CompletedTask; + } + + [LoggerMessage(LogLevel.Critical, ErrorMessage)] + private static partial void LogAlreadySet(ILogger logger); + } +} + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterModule.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterModule.cs index 0da68964db..f594757a18 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterModule.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterModule.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Web; +using Microsoft.AspNetCore.SystemWebAdapters.Hosting; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.SystemWebAdapters; @@ -24,7 +25,10 @@ public void Init(HttpApplication context) throw new ArgumentNullException(nameof(context)); } - var serviceProvider = context.Application.GetServiceProvider(); + context.Application.EnsureSystemWebAdapterBuilderBuilt(); + + var serviceProvider = HttpApplicationHost.Current.Services; + if (serviceProvider is not null) { _scope = serviceProvider.CreateScope(); diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixture.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixture.cs index 2c11138c3a..36cb0f9881 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixture.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixture.cs @@ -15,6 +15,10 @@ public AspireFixture() var builder = await DistributedApplicationTestingBuilder .CreateAsync(); + // Must set the HTTP endpoint + builder.Configuration["ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL"] = "https://localhost:21002"; + builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = null; + var app = await builder.BuildAsync(); await app.StartAsync(); diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests.csproj b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests.csproj index 202d25ab52..f98cb517be 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests.csproj +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests.csproj @@ -1,7 +1,7 @@  - net9.0-windows + net10.0-windows enable enable false