I have a controller to register user on site and it works correctly.(It has RegisterViewModel)
public class RegisterUserViewModel
{
public string Mobile { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
public string Email { get; set; }
}
and its register function:
public async Task<IActionResult> Register(RegisterUserViewModel registerUserViewModel)
{
if (ModelState.IsValid)
{
var result = await _userService.RegisterUser(registerUserViewModel);
switch (result)
{
case RegisterUserResult.Error:
ModelState.AddModelError(string.Empty, "failed");
TempData[ErrorMessage] = "failed"
break;
case RegisterUserResult.UserExist:
ModelState.AddModelError("Email", "Registered Before");
break;
case RegisterUserResult.Success:
ViewBag.active = x;
return View("SuccessRegister",registerUserViewModel);
}
}
return View(registerUserViewModel);
}
but for activation his email I write a function with different view model for writing clean code and get just active code from data base. it works alone too correctly
public class EmailActiveAccountViewModel
{
public string EmailActiveCode { get; set; }
}
and its function works correctly.
public async Task<IActionResult>ActiveEmailAccount(EmailActiveAccountViewModel activeCode)
{
if (ModelState.IsValid)
{
var result = await _userService.ActiveAccount(activeCode);
ViewData["Active"] = result;
}
return View(activeCode);
}
I pass activecode from viewbag:
View:
<div class="alert alert-success">
<h3> @Model.FirstName @Model.LastName dear!</h3>
<p>successful register "@Model.Email" </p>
<p>
<a href="https://localhost:44385/active?EmailActiveCode=@ViewBag.active">Activation</a>
</p>
</div>
with this way active code goes to function: ActiveEmailCode
If I set a separate link in the web , "ActiveAccount" funcation works correctly,
email send to user's email correctly but "ActiveAccount" funcation does not work. EmailActiveCode=@ViewBag.active does not come to the user's email
I set with gmail smtp and change the setting of gmail as a help links
see the pic:
if i set the link in pasge is correct:

but after send to email ,it does not work, user recive the email, but this linl does not work , becasue emailactivecode does not come to function just in email
