Ho aggiunto la verifica della posta elettronica al modello di identità ASP.NET all'interno di un progetto MVC ASP.NET standard. La seguente riga provoca un AccessViolationException:Url.Action() causa System.AccessViolationException
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme);
UPDATE:quanto inspiegabile come il problema era sparito. Cercherò di capire cosa l'ha fatto andare via. Per la mia preoccupazione, non sono a conoscenza di cambiamenti radicali alla soluzione.
Il metodo di controllo completo per conto registrazione degli utenti sembra che:
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
string callbackUrl;
try
{
string requestScheme = Request.Url.Scheme;
object confirmModel = new { userId = user.Id, code = code };
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme); // TODO: Fails somehow!
}
catch (Exception ex)
{
Debug.WriteLine(ex);
callbackUrl = "https://localhost:43000/Account/ConfirmEmail?userid=" + user.Id + "&code=" + code;
}
await
UserManager.SendEmailAsync(
userId: user.Id,
subject: "Verify it's you",
body: "Please confirm your email address by clicking <a href=\"" + callbackUrl + "\">here</a>");
return View("CheckYourEmail");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
Purtroppo non c'è eccezione interna o qualcosa di utile.
Il blocco catch() risolve il problema come soluzione alternativa.
Ma sono davvero curioso di cosa stia succedendo qui.
Puoi copiare e incollare il testo esatto dell'intero output di 'ex.ToString()' nella tua domanda? –
Qual è la traccia dello stack come nell'eccezione? –