How to redirect page automatically on session expire page when session expired in asp.net core 6.0 C#?
Loading
How to redirect page automatically on session expire page when session expired in asp.net core 6.0 C#?
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.
piyush goyalPosted Feb 16, 2023, 12:18 PM
Thanks for your time and help but we don't have the startup.cs in core 6.0.
Can you please provide me a running application with this functionality only in core 6.0
Tuhin PaulPosted Feb 16, 2023, 11:58 AM
Thanks @Jignesh, for sharing your implementation.
Jignesh KumarPosted Feb 16, 2023, 11:28 AM
Hi Piyush,
Please do needful as below in startup.cs page,
Add the following code to the Configure method in the Startup.cs file:
Create new SessionExpiredMiddleware.cs file:
Tuhin PaulPosted Feb 16, 2023, 11:08 AM
Bro! You have to follow 3 easy steps:
1. Create a new Razor page named "SessionExpired.cshtml" that will be displayed when the session expires. This page should include a message informing the user that their session has expired and providing a link to return to the login page.
2. In the Program.cs file, configure the session middleware to set the timeout for the session and to redirect to the SessionExpired page when the session expires. You can also set the cookie name and other options as needed.
3. Finally, in your other Razor pages or controllers, use the session to store and retrieve data as needed. The session will automatically expire after the timeout period specified in the configuration. If the user tries to access a page with an expired session, they will be redirected to the SessionExpired page.
DONE!
Your users will be automatically redirected to the SessionExpired page when their session expires.
Naimish MakwanaPosted Feb 16, 2023, 11:06 AM
Hello Piyush,
Please refer below link:
https://stackoverflow.com/a/66107308/3054222
https://stackoverflow.com/a/71474464/3054222
Thanks
Naimish