尝试使用 Identity.UserManager 确认电子邮件时出错

问题描述 投票:0回答:1

我正在使用 SendGrid API 发送验证电子邮件。它在 SendGrid 和 Azure 上运行良好,我的应用程序之前托管在 Azure 上。但是,部署到 IIS 服务器后,在我的 VPS 上,当我尝试确认从 SendGrid 返回的用户电子邮件时,出现错误:

var result = await _userManager.ConfirmEmailAsync(user, token);

从事件查看器日志中,警告是:

Category: Microsoft.AspNetCore.Identity.UserManager
EventId: 9
SpanId: 3830373dac59b144
TraceId: 2654243922e29b43b4ade992e096d1d3
ParentId: 0000000000000000
RequestId: 800000fd-0001-f300-b63f-84710c7967bb
RequestPath: /Identity/Account/EmailConfirmation
ActionId: 65237a3f-acf5-4dda-93d6-c37a34f1a351
ActionName: Kepler.MVC.Areas.Identity.Controllers.AccountController.EmailConfirmation (Kepler.MVC)

VerifyUserTokenAsync() failed with purpose: EmailConfirmation for user.

上面的错误是关于令牌验证吗?为什么会发生?

除此之外,抛出错误异常,事件查看器日志上的错误是:

Category: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer
EventId: 2
SpanId: 3830373dac59b144
TraceId: 2654243922e29b43b4ade992e096d1d3
ParentId: 0000000000000000
RequestId: 800000fd-0001-f300-b63f-84710c7967bb
RequestPath: /Identity/Account/EmailConfirmation

Connection ID "17509995357122068732", Request ID "800000fd-0001-f300-b63f-84710c7967bb": An unhandled exception was thrown by the application.

Exception: 
System.NullReferenceException: Object reference not set to an instance of an object.
   at AspNetCore.Views_Shared_Error.ExecuteAsync() in C:\Users\gutox\source\repos\Gutobarroso\GooGit\Kepler.MVC\Views\Shared\Error.cshtml:line 9
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

我注意到 Error.cshtml 的路径指向我的本地主机 C:\Users\gutox\source epos\Gutobarroso\GooGit\Kepler.MVC\Views\Shared\Error.cshtml:第 9 行

但是我已经完成了部署到 IIS 服务器托管。我不再使用本地主机了。如何/在哪里可以更改它?

我正在使用 .NET 5、IIS 10。

c# asp.net-core asp.net-core-mvc .net-5 asp.net-core-identity
1个回答
0
投票

我的错。我在回调 url 令牌的末尾传递了一个单引号。所以,比较时,代币是不同的。

© www.soinside.com 2019 - 2024. All rights reserved.