dotnet / dotnet/AspNetCore.Docs
UUF: Fix `AuthMessageSenderOptions` reg in auth tutorial
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 109
Description
### Description
**Problem**
Users following the "Account confirmation and password recovery in ASP.NET Core" tutorial are experiencing an error: "`` throws error as undefined" when implementing email functionality.
**Root Cause**
The current documentation shows this code for registering the options:
```csharp
builder.Services.Configure(builder.Configuration);
```
This doesn't properly bind to any specific configuration section, causing the `AuthMessageSenderOptions` class to be undefined when injected into services.
**Proposed Solution**
Update the "Configure app to support email" section in the tutorial to properly register the `AuthMessageSenderOptions` class:
```csharp
// Add EmailSender as a transient service
builder.Services.AddTransient();
// Register the AuthMessageSenderOptions configuration instance
builder.Services.Configure(options =>
{
// Bind directly to the user secrets key
options.SendGridKey = builder.Configuration["SendGridKey"];
});
```
The key change here is in how the `AuthMessageSenderOptions` class gets registered.
Instead of using `builder.Services.Configure(builder.Configuration)`,
which doesn't properly bind to any specific configuration section, this update explicitly binds
the SendGridKey from the configuration to the options object.
This prevents the "`` throws error as undefined" error that can occur
when the options class isn't properly registered in the dependency injection container.
### Page URL
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-9.0&tabs=visual-studio
### Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authentication/accconfirm.md
### Document ID
98e7aacb-2a01-d581-9b03-bfef2893163e
### Platform Id
8efad4e0-06aa-bbe0-6133-4092aed18e42
### Article author
@wadepickett
### Metadata
* ID: fe1bea60-d173-f6d2-3559-b147699e295a
* PlatformId: 8efad4e0-06aa-bbe0-6133-4092aed18e42
* Service: **aspnet-core**
* Sub-service: **security**
[Related Issues](https://github.com/dotnet/AspNetCore.Docs/issues?q=is%3Aissue+is%3Aopen+98e7aacb-2a01-d581-9b03-bfef2893163e)
Contributor guide
Assessment
This issue has not been assessed yet.