Hi,
I am using asp.net core MVC .net 6.0 version. I have set some cookies values in my controller which i want to access in my view.
How can i access that value in my razor page.
I want to access role using httpcontext.
[HttpPost]
public IActionResult Login(LoginRequest authenticationRequest)
{
if (ModelState.IsValid)
{
AccountApiCall accountApiCall = new AccountApiCall(Configuration["PAPI"]);
var Response = accountApiCall.PostAPIcall<AuthenticationResponse>(authenticationRequest, "Home/Login");
if (Response.userdetails != null)
{
string FUllName = Response.userdetails.firstName + " " + Response.userdetails.lastName;
HttpContext.Response.Cookies.Append("Token", Response.userdetails.token);
HttpContext.Response.Cookies.Append("Email", Response.userdetails.email);
HttpContext.Response.Cookies.Append("FullName", FUllName);
HttpContext.Response.Cookies.Append("Role", Response.userdetails.role);
HttpContext.Response.Cookies.Append("UserId", Response.userdetails.userID);
TempData["Role"] = Response.userdetails.role;
TempData.Peek("Role");
if (Response.userdetails.role == RoleHelper.Admin)
return RedirectToAction("Index", "List");
else
return RedirectToAction("Index", "Dashboard");
}
else
{
ModelState.AddModelError("CustomError", Response.message);
return View();
}
}
else
{
return View();
}
}
@{
string Role = Convert.ToString(TempData["Role"]);
}
<div class="sidebar-heading py-4 border-bottom">
<img src="~/assets/sidelogo.svg" alt="">
<div class="user-wrapper d-flex pt-5">
<a href="#">
<img src="assets/user-2.svg" class="img-fluid" alt="">
</a>
<div class="user-description ms-3">
<p class="mb-0">@TempData["FullName"]</p>
<span class="time">@Role</span>
</div>
</div>
</div>
<div class="list-group list-group-flush my-4 ms-2" id="DataNav">
@if (Role == "Admin")
{
<a href="@Url.Action("Index","ICD")"
class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">medication</span><span class="ms-1 d-none d-sm-inline">Masters</span>
</a>
<a href="@Url.Action("List","Provider")"
class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">person</span>
<span class="ms-1 d-none d-sm-inline">Manage Providers</span>
</a>
<a href="@Url.Action("Index","Patient")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2"> personal_injury</span><span class="ms-1 d-none d-sm-inline">Patients</span>
</a>
<a href="@Url.Action("Index","Order")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2"> receipt_long</span><span class="ms-1 d-none d-sm-inline">Orders</span>
</a>
<a href="@Url.Action("Index","Settings")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">settings</span><span class="ms-1 d-none d-sm-inline">Settings</span>
</a>
}
else if (Role == "Provider")
{
<a href="@Url.Action("Index","Dashboard")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">dashboard</span><span class="ms-1 d-none d-sm-inline">Dashboard</span>
</a>
<a href="@Url.Action("Index","PrescriptionPlan")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">person</span><span class="ms-1 d-none d-sm-inline">Manage Prescription Plans</span>
</a>
<a href="@Url.Action("PatientList","Patient")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">person</span><span class="ms-1 d-none d-sm-inline">Manage Patients</span>
</a>
<a href="@Url.Action("Index","Settings")" class="list-group-item list-group-item-action d-flex">
<span class="material-symbols-outlined me-2">settings</span><span class="ms-1 d-none d-sm-inline">Settings</span>
</a>
}
</div>
<div class="list-group list-group-flush logout-wrapper ms-2">
<a href="@Url.Action("Login","Account")" class="btn btn-logout d-flex">
<span class="material-symbols-outlined">logout</span>
<span class="ms-1 d-sm-inline">Logout</span>
</a>
</div>