【问题标题】:Error trying to confirm an email using Identity.UserManager尝试使用 Identity.UserManager 确认电子邮件时出错
【发布时间】:2021-11-01 04:30:31
【问题描述】:

我正在使用 SendGrid API 发送验证电子邮件。它在我的应用程序之前托管的 SendGrid 和 Azure 上运行良好。但是,在我的 VPS 上部署到 IIS 服务器后,当我尝试确认从 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\repos\Gutobarroso\GooGit\Kepler.MVC\Views\Shared\Error.cshtml:line 9

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

我将不胜感激。我正在使用 .Net 5、IIS 10。

【问题讨论】:

    标签: c# asp.net-identity .net-5 asp.net5


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 2015-07-27
      • 2021-09-01
      • 2020-05-13
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 2019-01-11
      相关资源
      最近更新 更多