
how can i use session in a controller class in asp.net?


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaya PrakashPosted May 9, 2024, 7:33 AM
Jayraj Chhaya
Actually i take web api controller in my asp.net project i just want to store that otp in session how
when i keep [EnableSessionState] getting assembly reference error could not be found
Jignesh KumarPosted May 8, 2024, 5:07 PM
Hello Jaya Prakash,
Please refer to this thread which has a very good explanation of the mvc core application,
you need to install the Nuget package for the session "Microsoft.AspNetCore.Session package",
https://www.c-sharpcorner.com/blogs/session-management-in-asp-net-core-mvc
Jaydeep PatilPosted May 8, 2024, 4:01 PM
Steps:
1. Configure session in startup class services and middleware section
2. Access inside the controller
Jaimin ShethiyaPosted May 8, 2024, 3:51 PM
Hello,
Please refer the below links,
In this link use the session in the API controller side.
https://www.researchgate.net/publication/371904967_Https_Session_Authentication_in_aspnet_Core_Web_API
Here is the link for, asp.net core mvc
https://dotnettutorials.net/lesson/sessions-in-asp-net-core-mvc/
Thanks
Jayraj ChhayaPosted May 8, 2024, 11:36 AM
Hi Jaya Prakash,
Please share error details or screen shot so I can help
Jaya PrakashPosted May 8, 2024, 11:20 AM
Jayraj Chhaya not working bro im using only asp.net not core
Jayraj ChhayaPosted May 8, 2024, 10:34 AM
You can access and utilize session variables within a controller class by leveraging the
Sessionproperty provided by theControllerbase class. This property allows you to store and retrieve session data easily.