aspnet / Templates

This repo is OBSOLETE - please see the README file for information
Other
151 stars 57 forks source link

Account/ConfirmEmail - NullReferenceException in Error.cshtml when providing incorrect token #865

Closed pejta2207 closed 6 years ago

pejta2207 commented 7 years ago

Description The issue is related to Individual Accounts Authentication template. It seems that providing incorrect authentication code for ConfirmEmail action in AccountController (e.g. token which already expired) should result in displaying error page. However, Razor throws an exception while generating the default error view:

NullReferenceException: Object reference not set to an instance of an object.
AspNetCore._Views_Shared_Error_cshtml+<ExecuteAsync>d__0.MoveNext() in Error.cshtml, line 9

Steps to reproduce

  1. Create new project with Individual Accounts Authentication template.
  2. Run the application.
  3. Register any user via the registration form.
  4. Retrieve UserId of the registered user.
  5. Try to confirm email with incorrect token, e.g. http://localhost:PORT/Account/ConfirmEmail?UserId={UserId}&Code=INVALID_CODE

Further technical details It's probably caused by the last line in ConfirmEmail action in AccountController:

var result = await _userManager.ConfirmEmailAsync(user, code);
return View(result.Succeeded ? "ConfirmEmail" : "Error");

When invalid token is passed, Error view is not provided with ErrorViewModel. When Model is accessed in 9th line of Error.cshtml (@if (Model.ShowRequestId)), it throws NullReferenceException.

Eilon commented 6 years ago

This issue was moved to aspnet/templating#80