
Step-1
Post your any code related problem to www.abctutorial.com
Follow the previous video and articles to complete the POS tutorials
We will show our logged-in username and roles in our top menu so that’s why we will use logged session variable to show the name and role.
- Please go to _Layout.cshtml view.
- We already worked in previous article this mentioned view so now update existing code by this code.
<span class="mr-2 d-none d-lg-inline text-gray-600 small"> @Session["Username"] [@Session["Role"]]</span>
Step-2
If we logged-in already using login panel then inside from application we should have a logout button where from we can logout. So here we will place our logout method trigger code from client side.
- Please go to _Layout.cshtml view.
- We already worked in previous article this mentioned view so now update existing code by this code.
<a class="btn btn-primary" href="@Url.Action("Logout","Home")">Logout</a>
Step-3
Here I am going to write some code which will session out and logout me from application and it will redirect me to login page.
- Please go to HomeController.
- Please write this below code to set null value in session and logout me from application.
public ActionResult Logout()
{
Session["Username"] = null;
Session["Role"] = null;
return RedirectToAction("Login");
}
- Now run the project.
- Then save data.