Asp.net - maintain a session while debugging and restoring a solution?

I am writing an asp.net web application. I wrote a login page that authenticates the user and stores their UserID in Session["UserID"] . On each page of the web application, a valid Session["UserID"] will be checked. If this is not valid, redirect the user to the login screen.

This works great, but it slows down my ability to debug every page on my website. Every time I make changes to the *.cs file, I need to press F6 to restore my solution. This destroys my session, which means that I need to return to the login screen, enter the username and password, click on the page I worked on, perform my tests, make changes to the code and repeat.

Is there a way to keep my session alive every time I create my solution again, so I don’t need to go to the login page every time?

+6
source share
2 answers

Unfortunately, I do not know that you will find any way around this restriction. Each time you build your project, you will start restarting the web application. Even if you use a persistent store to store sessions, you will lose the session cookie set in your browser.

You can add the “remember me” function to your application. You need to do a small reevaluation to save current user authentication information in a data warehouse that is less volatile than the state of an ASP.NET session. In addition, you would store an index of this information in a cookie, which would be more robust than a session cookie.

This is the best I can come up with, or at least the best I can come up with without any significant extensions to the .NET security providers. However, take it with salt - I have never tried to solve this problem before, and I hardly consider myself an expert in all ASP.NET related sessions.

+3
source

The reason you lose the session is because your application restarts when it is written to the application folder. In fact, the same thing happens when you publish your application, each user who is currently logged in will lose his session.

This is intentional because they have no way of knowing that the DLL that you used on your page still exists or not. Therefore, instead, they track the folders themselves and start a restart when they are written.

There is no workaround for this. This is actually a function that saves you time (most of the time), imagine you are tracking memory corruption errors because pointers are moving in your code!

+2
source

Source: https://habr.com/ru/post/885844/


All Articles