Hi All
I have created a blazor WASM PWA .Net6 application that allows a user to register with some basic details.
Once the user registers the application sends a email confirmation link with a link and token to validate the email address.
This is all working fine in production I can register and confirm email via the link provided.
When I host the application on my local machine IIS the application works but when I register a new account and use the email confirmation link I keep getting a message saying "Sorry, there's nothing at this address."
this is happening on all the pages that uses "return View("xyz"). Even when I use the passwords reset function that also returns a view I get the same message "Sorry, there's nothing at this address.". This is only happening on controllers that returns a view and it is only happening when the app is hosted. I don't see any errors in DEV tools in chrome. When I click on the email confirmation link it takes me to the correct page using this link:
https://localhost/confirmemail?token=CfDJ8KzzpED9Bh1EllkgzIX2Irm9CPTd%2FsBR2lNzn2kYtjOAiFsoeJ44Crm8%2B4HVudPtOipeshkSB5cNLKXNtUNnPzqS%2FbNeOtCqRJ4QfRWaPR1YD8Nrss6MxRrUotCWgefDhTjUnTOUnJ19A3QiiB%2Fx4BZaUjBnMCnq609ixEwnoZ%2BqWpQOsE2ptyczBLpHtkV4OSIbVoc6YbmB52hzAULOEWbC8Y4%2Bc5N6ENVso69%2BemCn%2FHSjOigHvKIUBMcViq68hg%3D%3D&email=JJK.Something@gmail.com
but displayed: "Sorry, there's nothing at this address.". if I do a ctrl+F5 it completes the email confirmation process and all is fine. But I cannot understand why I have to do a refresh "CTRL+F5" to complete the email confirmation or password reset this is only when the app is hosted and its only on Return View all other razor pages are working as expected.
My account controller to generate the link on login uses the following code:
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var confirmationLink = Url.Link("Confirmation", new { token, email = user.Email });
await _emailSender.SendEmailAsync(user.Email, "Account Confirmation Link - CrimeLogger",
$"Please confirm your account by clicking <a href=\"" + confirmationLink + "\">here</a>");
The email is sent and I use the email link to confirm registration:
The link points to the following controller:
[Route("ConfirmEmail", Name = "Confirmation")]
[ApiController]
[Authorize]
public class EmailController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
public EmailController(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ConfirmEmail(string token, string email)
{
var user = await _userManager.FindByNameAsync(email);
if (user == null)
return View("Error");
var result = await _userManager.ConfirmEmailAsync(user, token);
if (result.Succeeded)
{
return View("ConfirmedEmail");
}
else
{
return View("emailconfirmerror");
}
it should load the view below: but it does not, only after CTRL+F5 does it load the below view. Any suggestions on where I can look to try and resolve this error. Remember this only happens when the app is hosted and only on Views I have cleared the browser cash and tried again but still same situation
@using Common
@using Microsoft.AspNetCore.Components
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
ViewData["Title"] = "ConfirmedEmail";
}
@inject NavigationManager NavigationManager
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>ConfirmEmail</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/app.css" rel="stylesheet" asp-append-version="true" />
</head>
<body>
<div class="row col-md-12" style="place-content:center;text-align:center">
<div class="card border">
<div class="card-body">
<h3 class="col-12 text-black text-center py-2">
Welcome to XYZ
</h3>
<div>
<p>Thank you for confirming your email. Please log in <a href="@SD.TempLink">here</a>.
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Thank you