I'm using send grid to send an email after a user is created and I'm following This tutorial Here http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity I even downloaded This tutorial and wrote code as it is
but it code breaks at this
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>.");
Its This third like
manager.SendEmail(uApp.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
Where code breaks
and the errors is like this
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()
and bla bla bla before this it was giving me an error on first line abot some token and stuff What is that I'm doing wrong
InvalidApiRequestException exception is the key.
The best way to handle errors using DeliverAsync() method is something like this:
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With