Url.Action () throws a System.AccessViolationException

I added email validation to the ASP.NET authentication model as part of the standard ASP.NET MVC project. The following line raises an AccessViolationException:

callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme); 

UPDATE: As inexplicable as the problem has disappeared. I will try to find out what made him leave. To my concern, I do not know of any major changes to the decision.

The complete user account control method for registering users is as follows:

 // 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 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); } 

Unfortunately, there is no internal exception or anything useful.

The catch () block solves the problem as a workaround.
But I'm really curious what is going wrong here.

+5
source share
1 answer

Instead of setting the confirmModel = ... object, use "dynamic confirmModel = ..." and see if it fixes it.

0
source

All Articles