Starts in:
0 DAY
20 HRS
55 MIN
17 SEC
Starts in:
0 D
20 H
55 M
17 S
Open Closed

SaasServiceHttpApiHost-terminated-unexpectedly-Error #7194


User avatar
0
kerem.kalemci created

Hello, I have a problem.

Volo.Abp.AbpInitializationException: An error occurred during ConfigureServicesAsync phase of the module HitFrame.SaasService.SaasServiceHttpApiHostModule, HitFrame.SaasService.HttpApi.Host, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. See the inner exception for details.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Extensions.DependencyInjection.AbpSwaggerGenServiceCollectionExtensions.AddAbpSwaggerGenWithOAuth(IServiceCollection services, String authority, Dictionary`2 scopes, Action`1 setupAction, String authorizationEndpoint, String tokenEndpoint)
   at HitFrame.Shared.Hosting.AspNetCore.SwaggerConfigurationHelper.ConfigureWithAuth(ServiceConfigurationContext context, String authority, Dictionary`2 scopes, String apiTitle, String apiVersion, String apiName) in C:\Users\hitsoftdevadm18\Desktop\atlassian-bitbucket-pipelines-runner\temp\79132501-1037-5832-acea-3435bd03b6a5\1715608337513\build\shared\HitFrame.Shared.Hosting.AspNetCore\SwaggerConfigurationHelper.cs:line 40
   at HitFrame.SaasService.SaasServiceHttpApiHostModule.ConfigureServices(ServiceConfigurationContext context) in C:\Users\hitsoftdevadm18\Desktop\atlassian-bitbucket-pipelines-runner\temp\79132501-1037-5832-acea-3435bd03b6a5\1715608337513\build\services\saas\src\HitFrame.SaasService.HttpApi.Host\SaasServiceHttpApiHostModule.cs:line 39
   at Volo.Abp.Modularity.AbpModule.ConfigureServicesAsync(ServiceConfigurationContext context)
   at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync()
   --- End of inner exception stack trace ---
   at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync()
   at Volo.Abp.AbpApplicationFactory.CreateAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionApplicationExtensions.AddApplicationAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction)
   at Microsoft.Extensions.DependencyInjection.WebApplicationBuilderExtensions.AddApplicationAsync[TStartupModule](WebApplicationBuilder builder, Action`1 optionsAction)

The code block:

  public override void ConfigureServices(ServiceConfigurationContext context)
  {
      // Enable if you need these
      // var hostingEnvironment = context.Services.GetHostingEnvironment();
      var configuration = context.Services.GetConfiguration();

      context.Services.AddAbpDbContext<SaasServiceDbContext>();
      JwtBearerConfigurationHelper.Configure(context, "SaasService");
      SwaggerConfigurationHelper.ConfigureWithAuth(
          context: context,
          authority: configuration["AuthServer:Authority"],
          scopes: new
              Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */ {
                  { "SaasService", "Saas Service API" }
              },
          apiTitle: "Saas Service API"
      );
      context.Services.AddCors(options =>
      {
          options.AddDefaultPolicy(builder =>
          {
              builder
                  .WithOrigins(
                      configuration["App:CorsOrigins"]
                          .Split(",", StringSplitOptions.RemoveEmptyEntries)
                          .Select(o => o.Trim().RemovePostFix("/"))
                          .ToArray()
                  )
                  .WithAbpExposedHeaders()
                  .SetIsOriginAllowedToAllowWildcardSubdomains()
                  .AllowAnyHeader()
                  .AllowAnyMethod()
                  .AllowCredentials();
          });
      });
      ConfigureHealthChecks(context);
  }

And;

public static void ConfigureWithAuth(
    ServiceConfigurationContext context,
    string authority,
    Dictionary<string, string> scopes,
    string apiTitle,
    string apiVersion = "v1",
    string apiName = "v1"
)
{
    context.Services.AddAbpSwaggerGenWithOAuth(
        authority: authority,
        scopes: scopes,
        options =>
        {
            options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
            options.DocInclusionPredicate((docName, description) => true);
            options.CustomSchemaIds(type => type.FullName);
            options.ResolveConflictingActions(apiDesc => apiDesc.First());
        });
}

11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please make sure the configuration["AuthServer:Authority"] has value first.

    Thanks.

  • User Avatar
    0
    kerem.kalemci created

    DNS_PROBE_FINISHED_NXDOMAIN error occured now. There no logs although there is stdoutlog open in the web.config.

    There is another problem in the copying of appsettings.json but I might take this into account after we solve this issue.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    DNS_PROBE_FINISHED_NXDOMAIN error occurred now.

    This doesn't sound like a web app error. Can you share the error details? you can check the windows event viewer.

  • User Avatar
    0
    guven.uysall created

    Hi,

    domain registrations need to be made to the server's host file.if you do not have the domain registration you provided, you will usually get this error.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thank guven.uysall for your advice.

  • User Avatar
    0
    kerem.kalemci created

    Hello,

    I imported the certificate with the command:

    New-SelfSignedCertificate -subject *.hitsoft.com.tr -DNsName testsaas.hitsoft.com.tr -CertStoreLocation Cert:\LocalMachine\My -NotAfter (Get-Date).AddYears(10)

    It is in the trusted root

    System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatchSystem.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

    The url is testsaas.hitsoft.com.tr

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can get a valid and free SSL certificate for your domain.

    https://www.google.com/search?q=get+a+free+ssl+certificate+from+let%27s+encrypt

  • User Avatar
    0
    kerem.kalemci created

    Is there a code block where we setup the pfx file in abp already?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
        var configuration = context.Services.GetConfiguration();
    
        PreConfigure<OpenIddictBuilder>(builder =>
        {
            builder.AddValidation(options =>
            {
                options.AddAudiences("MyProjectName");
                options.UseLocalServer();
                options.UseAspNetCore();
            });
        });
    
        if (!hostingEnvironment.IsDevelopment())
        {
            PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
            {
                options.AddDevelopmentEncryptionAndSigningCertificate = false;
            });
    
            PreConfigure<OpenIddictServerBuilder>(serverBuilder =>
            {
                serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "00000000-0000-0000-0000-000000000000");
                serverBuilder.SetIssuer(new Uri(configuration["AuthServer:Authority"]!));
            });
        }
    }
    

    Generating a Signing Certificate

    In the production environment, you need to use a production signing certificate. ABP Framework sets up signing and encryption certificates in your application and expects an openiddict.pfx file in your application.

    This certificate is already generated by ABP CLI, so most of the time you don't need to generate it yourself. However, if you need to generate a certificate, you can use the following command:

    dotnet dev-certs https -v -ep openiddict.pfx -p 00000000-0000-0000-0000-000000000000
    

    00000000-0000-0000-0000-000000000000 is the password of the certificate, you can change it to any password you want.

    It is recommended to use two RSA certificates, distinct from the certificate(s) used for HTTPS: one for encryption, one for signing.

    For more information, please refer to: https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html#registering-a-certificate-recommended-for-production-ready-scenarios

    Also, see the Configuring OpenIddict documentation for more information.

  • User Avatar
    0
    kerem.kalemci created

    Hi there.

    Normally the command;

    New-SelfSignedCertificate -subject *.hitsoft.com.tr -DNsName testsaas.hitsoft.com.tr -CertStoreLocation Cert:\LocalMachine\My -NotAfter (Get-Date).AddYears(10)

    makes this work for the url testsaas.hitsoft.com.tr.

    What is missing? We don't want let's encrypyt.

    It complains : ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have no experience with New-SelfSignedCertificate command.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06