import CustomDomainEndpointNotice from '@/mdx-components/CustomDomainEndpointNotice';

Open `Startup.cs` (or `Program.cs`) and add the following code to register Logto authentication middleware:

<Code title="Program.cs" className="language-csharp">
{`using Logto.AspNetCore.Authentication;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLogtoAuthentication(options =>
{
  options.Endpoint = "${props.endpoint}";
  options.AppId = "${props.app.id}";
  options.AppSecret = "${props.secrets[0]?.value ?? props.app.secret}";
});

app.UseAuthentication();`}
</Code>

<br/>

<CustomDomainEndpointNotice />

The `AddLogtoAuthentication` method will do the following things:

- Set the default authentication scheme to `LogtoDefaults.CookieScheme`.
- Set the default challenge scheme to `LogtoDefaults.AuthenticationScheme`.
- Set the default sign-out scheme to `LogtoDefaults.AuthenticationScheme`.
- Add cookie and OpenID Connect authentication handlers to the authentication scheme.
