다음을 통해 공유


원격 앱 설정

중요합니다

프레임워크 및 코어 애플리케이션은 동일한 가상 디렉터리 레이아웃을 사용해야 합니다.

가상 디렉터리 설정은 시스템 내의 경로 생성, 권한 부여 및 기타 서비스에 사용됩니다. 이 시점에서는 ASP.NET Framework 작동 방식 때문에 다른 가상 디렉터리를 사용하도록 설정하는 신뢰할 수 있는 메서드가 없습니다.

일부 증분 업그레이드 시나리오에서는 새 ASP.NET Core 앱이 원래 ASP.NET 앱과 통신할 수 있도록 하는 것이 유용합니다.

이렇게 하면 다음과 같은 일반적인 시나리오가 가능합니다.

구성 값

ASP.NET Core 앱이 ASP.NET 앱과 통신할 수 있도록 하려면 각 앱을 약간 변경해야 합니다.

두 애플리케이션에서 다음 두 가지 구성 값을 구성해야 합니다.

  • RemoteAppApiKey: 두 애플리케이션 간에 공유되는 키( GUID로 구문 분석 가능해야 합니다). 이 값은 다음과 같은 12345678-1234-1234-1234-123456789012GUID 값이어야 합니다.
  • RemoteAppUri: 원격 ASP.NET Framework 애플리케이션의 URI입니다(ASP.NET Core 애플리케이션 구성에서만 필요). ASP.NET Framework 앱이 호스트되는 전체 URL(예: https://localhost:44300 또는 https://myapp.example.com.)이어야 합니다.

ASP.NET Framework 애플리케이션 구성

중요합니다

ASP.NET Framework 애플리케이션은 SSL을 사용하도록 설정된 상태로 호스트되어야 합니다. 증분 마이그레이션을 위한 원격 앱 설정에서는 외부에서 직접 액세스할 필요가 없습니다. 프록시를 통해 클라이언트 애플리케이션에서만 액세스를 허용하는 것이 좋습니다.

ASP.NET Framework 애플리케이션의 경우 web.config 섹션의 <appSettings>에 다음 값을 추가합니다.

중요합니다

ASP.NET Framework는 web.config에 appSettings를 저장합니다. 그러나 구성 작성기를 사용하여 다른 원본(예: 환경 변수)에서 검색할 수 있습니다. 이렇게 하면 이 설정에서 로컬 및 원격 애플리케이션 간에 구성 값을 훨씬 쉽게 공유할 수 있습니다.

<appSettings>
  <add key="RemoteAppApiKey" value="..." />
</appSettings>

ASP.NET Core 클라이언트의 요청을 처리할 수 있도록 애플리케이션을 구성하려면 다음을 설정합니다.

  1. NuGet 패키지 설치 Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices

  2. 파일의 Application_Start 메서드에 구성 코드를 추가하십시오 Global.asax.cs .

    protected void Application_Start()
    {
        HttpApplicationHost.RegisterHost(builder =>
        {
            builder.AddSystemWebAdapters()
                .AddRemoteAppServer(options =>
                {
                    // ApiKey is a string representing a GUID
                    options.ApiKey = System.Configuration.ConfigurationManager.AppSettings["RemoteAppApiKey"];
                });
        });
    
        // ...existing code...
    }
    
  3. NuGet에 의해 SystemWebAdapterModule 모듈이 web.config에 이미 추가되지 않은 경우 추가하십시오. 이 모듈 구성은 IIS 호스팅 시나리오에 필요합니다. SystemWebAdapterModule ASP.NET Core에 SDK 스타일 프로젝트를 사용하는 경우 모듈이 자동으로 추가되지 않습니다.

      <system.webServer>
        <modules>
    +      <remove name="SystemWebAdapterModule" />
    +      <add name="SystemWebAdapterModule" type="Microsoft.AspNetCore.SystemWebAdapters.SystemWebAdapterModule, Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices" preCondition="managedHandler" />
        </modules>
    </system.webServer>
    

ASP.NET 핵심 애플리케이션 구성

ASP.NET Core 애플리케이션의 경우 다음 값을 추가합니다 appsettings.json.

{
  "RemoteAppApiKey": "...",
  "RemoteAppUri": "https://localhost:44300"
}

ASP.NET 앱에 요청을 보낼 수 있도록 ASP.NET Core 앱을 설정하려면 System.Web 어댑터 서비스를 등록한 후 호출 AddRemoteAppClient 하여 원격 앱 클라이언트를 구성합니다 AddSystemWebAdapters.

Program.cs 파일에 이 구성을 추가하세요.

builder.Services.AddSystemWebAdapters()
    .AddRemoteAppClient(options =>
    {
        options.RemoteAppUrl = new(builder.Configuration["RemoteAppUri"]);
        options.ApiKey = builder.Configuration["RemoteAppApiKey"];
    });

ASP.NET 및 ASP.NET Core 앱이 모두 업데이트되면 필요에 따라 확장 메서드를 사용하여 원격 앱 인증 또는 원격 세션을 설정할 수 있습니다.

프록시 사용 활성화

ASP.NET Core 애플리케이션에서 ASP.NET Framework 애플리케이션으로의 프록시를 사용하도록 설정하려면 타의 추종을 불허하는 요청을 레거시 애플리케이션으로 전달하는 대체 경로를 설정할 수 있습니다. 이렇게 하면 ASP.NET Core 앱이 마이그레이션된 기능을 처리하는 동시에 마이그레이션되지 않은 기능에 대한 원래 앱으로 되돌아가는 점진적인 마이그레이션이 가능합니다.

  1. 최신 지침에 따라 YARP(또 다른 역방향 프록시) NuGet 패키지를 설치합니다.

  2. 필요한 using 선언을 Program.cs에 추가합니다.

    using Microsoft.Extensions.Options;
    using Microsoft.AspNetCore.SystemWebAdapters;
    
  3. Program.cs에 역방향 프록시 서비스를 등록하세요.

    builder.Services.AddReverseProxy();
    
  4. 앱을 빌드하고 다른 미들웨어를 구성한 후 대체 경로 매핑을 추가합니다.

    var app = builder.Build();
    
    // Configure your other middleware here (authentication, routing, etc.)
    
    // Map the fallback route
    app.MapForwarder("/{**catch-all}", app.Services.GetRequiredService<IOptions<RemoteAppClientOptions>>().Value.RemoteAppUrl.OriginalString)
    
        // Ensures this route has the lowest priority (runs last)
        .WithOrder(int.MaxValue)
    
        // Skips remaining middleware when this route matches
        .ShortCircuit();
    
    app.Run();
    

설정 Aspire 조율

중요합니다

이 통합은 현재 미리 보기로 제공되며 NuGet.org 시험판 패키지로 게시됩니다. 패키지를 추가할 때 도구에서 시험판 패키지를 사용하도록 설정합니다(예: Visual Studio의 NuGet 패키지 관리자에서 선택 Include prerelease 하거나 .NET CLI와 동등한 시험판 옵션을 사용).

  1. ASP.NET Framework 애플리케이션에 대한 오케스트레이션 추가 Aspire

  2. 새로운 ASP.NET Core 애플리케이션을 솔루션에 추가하고 그것을 Aspire 오케스트레이션에 추가합니다.

  3. Aspire.Hosting.IncrementalMigration AppHost 프로젝트에 패키지를 추가합니다.

  4. 증분 마이그레이션 확장을 사용하여 프레임워크 애플리케이션을 로컬로 호스트하고 증분 마이그레이션 대체를 구성하도록 IIS Express를 구성합니다.

    var builder = DistributedApplication.CreateBuilder(args);
    
    // Add ASP.NET Framework app with IIS Express
    var frameworkApp = builder.AddIISExpressProject<Projects.FrameworkApplication>("framework");
    
    // Add ASP.NET Core app with fallback to Framework app
    var coreApp = builder.AddProject<Projects.CoreApplication>("core")
        .WithIncrementalMigrationFallback(frameworkApp, options =>
        {
            options.RemoteSession = RemoteSession.Enabled;
            options.RemoteAuthentication = RemoteAuthentication.DefaultScheme;
        });
    
    builder.Build().Run();
    
  5. 지원하려는 시나리오에 대한 증분 마이그레이션 대체 옵션을 구성합니다.

ASP.NET Framework를 지원하도록 ServiceDefaults 구성

  1. 애플리케이션에 패키지를 Aspire.Microsoft.AspNetCore.SystemWebAdapters 추가합니다.

  2. .NET Framework를 지원하도록 ServiceDefaults 프로젝트를 업데이트합니다. 이는 기본 ServiceDefaults를 기반으로 하며, 사용자 지정한 항목이 있는 경우 다를 수 있습니다.

    • 대상 프레임워크를 여러 대상을 지원하도록 업데이트합니다.

      - <TargetFramework>net10.0</TargetFramework>
      + <TargetFrameworks>net481;net10.0</TargetFrameworks>
      
    • 다른 프레임워크를 고려하도록 PackageReferences를 업데이트합니다.

      <ItemGroup>
          <PackageReference Include="Microsoft.Extensions.Http.Resilience" />
          <PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
          <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
          <PackageReference Include="OpenTelemetry.Extensions.Hosting" />
          <PackageReference Include="OpenTelemetry.Instrumentation.Http" />
          <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
          <PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" />
      </ItemGroup>
      
      <ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
          <FrameworkReference Include="Microsoft.AspNetCore.App" />
          <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
      </ItemGroup>
      
      <ItemGroup Condition=" '$(TargetFramework)' == 'net481' ">
          <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
          <PackageReference Include="OpenTelemetry.Instrumentation.AspNet" />
      </ItemGroup>
      
    • 원격 분석을 사용하도록 설정하려면 메트릭 및 추적 등록을 업데이트합니다.

              builder.Services.AddOpenTelemetry()
                  .WithMetrics(metrics =>
                  {
                      metrics
      + #if NET
                          .AddAspNetCoreInstrumentation()
      + #else
      +                   .AddAspNetInstrumentation()
      + #endif
                          .AddSqlClientInstrumentation()
                          .AddHttpClientInstrumentation()
                          .AddRuntimeInstrumentation();
                  })
                  .WithTracing(tracing =>
                  {
                      tracing.AddSource(builder.Environment.ApplicationName)
      + #if NET
                          .AddAspNetCoreInstrumentation()
      + #else
      +                   .AddAspNetInstrumentation()
      + #endif
                          .AddSqlClientInstrumentation()
                          .AddHttpClientInstrumentation();
                  });
      
    • ASP.NET Core에만 적용되는 기본 엔드포인트를 사용하지 않도록 설정합니다.

      + #if NET
          public static WebApplication MapDefaultEndpoints(this WebApplication app)
          {
              // Default endpoint registrations
          }
      + #endif
      

    ASP.NET Core 및 ASP.NET Framework를 모두 지원하는 다중 대상 ServiceDefaults 구성의 전체 작업 예제는 System.Web 어댑터 리포지토리의 샘플 Extensions.cs 파일을 참조하세요 https://github.com/dotnet/systemweb-adapters/blob/main/samples/ServiceDefaults/Extensions.cs.

ASP.NET Framework 애플리케이션 구성

  1. ServiceDefaults 프로젝트 참조

  2. 파일의 Application_Start 메서드에 구성 코드를 추가하십시오 Global.asax.cs .

    protected void Application_Start()
    {
        HttpApplicationHost.RegisterHost(builder =>
        {
            builder.AddServiceDefaults();
            builder.AddSystemWebAdapters();
        });
    }
    

ASP.NET 핵심 애플리케이션 구성

  1. ServiceDefaults 프로젝트 참조

  2. Programs.cs System.Web 어댑터를 추가합니다.

    var builder = WebApplication.CreateBuilder();
    
    builder.AddServiceDefaults();
    + builder.AddSystemWebAdapters();
    
    ...
    
    var app = builder.Build();
    
    ...
    
    + // Must be placed after routing if manually added
    + app.UseSystemWebAdapters();
    
    ...
    
    + app.MapRemoteAppFallback()
    +
    +   // Optional, but recommended unless middleware is needed
    +   .ShortCircuit();
    
    app.Run();
    

이 구성을 사용하면:

  1. 로컬 경로가 우선합니다. ASP.NET Core 애플리케이션에 일치하는 경로가 있는 경우 로컬에서 요청을 처리합니다.
  2. 레거시 앱으로 대체: 일치하지 않는 요청은 ASP.NET Framework 애플리케이션에 자동으로 전달됩니다.
  3. 미들웨어 최적화: 이 메서드는 .ShortCircuit() 요청을 전달할 때 불필요한 미들웨어 실행을 방지합니다.

이 설정을 사용하면 사용자가 단일 엔드포인트를 통해 마이그레이션된 기능과 레거시 기능에 모두 액세스할 수 있는 증분 마이그레이션 중에 원활한 사용자 환경을 사용할 수 있습니다.