Home > database >  Assign a custom key to a session in c#
Assign a custom key to a session in c#

Time:05-26

I'm building a .NET 6 Core MVC Application In which I want to create a session whose key is "customer". And then I want to check on each page whether that session is valid or not. How can I do this?

CodePudding user response:

.1st Store your key value in a session.

Session["Key"]="customer"

.2nd Check your session value in another page if the value is valid or not.

if(Session["Key"].ToString()=="customer")
{
//valid action
}
else
{
//invalid action
}
  • Related