1

I am trying to raise docker compose for my services, and I want them to use https protocol to communicate, so I wrote something like this in my Program.cs file:

builder.WebHost.ConfigureKestrel(options =>
{
    options.ListenAnyIP(8081, listenOptions =>
    {
        try
        {
            listenOptions.UseHttps("/https/LRA.sertificate.pfx", "1234");
        }
        catch (Exception ex)
        {
            Console.WriteLine("HTTPS error: " + ex.Message);
        }
    });

    options.ListenAnyIP(8080);
})

and it worked.

After that, I tried to replace it to shared project (class lib) because it can be used in different services and create an extension method like this:

using Microsoft.AspNetCore.Hosting;

namespace LRA.Account.Application.Extension;

public static class SslSertificateInjection
{
    public static IWebHostBuilder AddApplicationServices(this IWebHostBuilder hosting)
    {
        hosting.ConfigureKestrel(options =>
        {
            options.ListenAnyIP(8081, listenOptions =>
            {
                try
                {
                    listenOptions.UseHttps("/https/LRA.sertificate.pfx", "1234");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("HTTPS error: " + ex.Message);
                }
            });

            options.ListenAnyIP(8080);
        });

        return hosting;
    }
}

But now I get an error:

CS1061 'IWebHostBuilder' does not contain a definition for 'ConfigureKestrel' and no accessible extension method 'ConfigureKestrel' accepting a first argument of type 'IWebHostBuilder' could be found (are you missing a using directive or an assembly reference?)

This method is in the Microsoft.AspNetCore.Hosting namespace, so I can't understand why it cannot be found.

I tried to install a lot of different packages to find maybe I missed one, but nothing helped. Maybe you can suggest either decision of a problem or other option to connect SSL certificate to my service so I won't need this part of the code.

2
  • and this question Commented Jun 27 at 8:25
  • 1
    @IvanPetrov yes, thats helped to me, thanks Commented Jun 27 at 14:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.