我正在使用发送网格在创建用户后发送电子邮件,我正在关注本教程 Here http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity 我什至下载了本教程并按原样编写了代码
但是它的代码在这里中断
string code = manager.GenerateEmailConfirmationToken(uApp.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, uApp.Id, Request);
manager.SendEmail(uApp.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
这是第三个喜欢
manager.SendEmail(uApp.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
代码中断的地方
错误是这样的
Exceptions.InvalidApiRequestException: Bad Request Check
Errors
for a list of errors returned by the API. at SendGrid.Web.d__c.MoveNext() -- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at SendGrid.Web.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at GCRweb.EmailService.d__0.MoveNext()
和啦啦啦啦 在此之前它在第一行给我一个关于一些 token 和东西的错误 我做错了什么
最佳答案
InvalidApiRequestException异常是关键。
使用 DeliverAsync() 方法处理错误的最佳方式是这样的:
try
{
await transportWeb.DeliverAsync(mensaje);
}
catch (InvalidApiRequestException ex)
{
var detalle = new StringBuilder();
detalle.Append("ResponseStatusCode: " + ex.ResponseStatusCode + ". ");
for (int i = 0; i < ex.Errors.Count(); i++)
{
detalle.Append(" -- Error #" + i.ToString() + " : " + ex.Errors[i]);
}
throw new ApplicationException(detalle.ToString(), ex);
}
关于c# - 错误请求 检查 `Errors` 以获取 API 返回的错误列表。在发送网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28878924/