I am storing full name of user in cookie after user successfully logs in with following code.
var res = await _signInManager.PasswordSignInAsync(suser.UserName, user.Password, user.Remember, false);
if (res.Succeeded)
{
Response.Cookies.Append("fullName", suser.FullName);
if (string.IsNullOrWhiteSpace(returnUrl))
return RedirectToAction("Dashboard", "User");
else
return Redirect(returnUrl);
}
I want to read this value in _Layout
page so that I can display full name in master page. According to solution mention in this post. I tried following sysntax in my _Layout
page.
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
@{
ViewBag.FullName = HttpContextAccessor.HttpContext.Request.Cookies["fullName"];
}
But I am not getting any value in ViewBag.FullName
. Am I doing something wrong here? How to read stored value in cookies in Views?