1

We have an application that establishes a session variable upon the user logging into our application. Its a single JSON string stores as session and we deserialize to an object when we want to access user profile items. Everything works as it should. The issue we have happens when we are developing. We validate for session upon load of a view. If session is null we redirect the user back to the login page. However while developing, we will have the page open and make a change to the HTML. Upon saving the change, Visual Studio recompiles the project and reloads the page. Well when the reload happens, and it checks for session, the session is null so it kicks the user back to the login page. This makes development time much longer. What is the best approach to overcoming this? Is it to save session in the database? Not sure how that will work either since we have to identify the user in some fashion to pull in the session data from the DB.

Any help would be great

Thanks

Steve C

zas1220
  • 11
  • 1
  • Are you using Microsoft's [ASP .NET Core session state management](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-5.0#session-state) or is this a custom implementation? – Adam Oct 20 '21 at 20:17
  • 1
    You can use the clause `#If DEBUG` to either set the session if it is null or ignore the redirect or whichever you find more appropriate check [this](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives) or [this](https://www.google.com/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/questions/2104099/c-sharp-if-then-directives-for-debug-vs-release&ved=2ahUKEwj3l92O9tnzAhUpD2MBHZJlD30QFnoECDYQAQ&usg=AOvVaw1JZqzqYBsdhSdYJXWroNi0) example – Modar Na Oct 20 '21 at 21:26
  • @AdamG -- We are using ASP.NET Core session state management. – zas1220 Oct 20 '21 at 21:56
  • @ModarNa -- Yea we can do that, but then we will have code for a fake session. We use session to know what use is in the application and if they perform a task (like update or insert), we pull the session employee ID, for example, to save with the task so we know who did it – zas1220 Oct 20 '21 at 21:59
  • 1
    @zas1220 -- at the point of code that you are checking for the session, you can use the `IF DEBUG` to simply assign the session if it is null, setting the session can be done using the same functions that you have when logging In, I can't be sure what to post here since there is no way to find out the code for setting the session in your project and where are you checking for the session, those 2 parts are to be used. – Modar Na Oct 21 '21 at 10:21
  • 1
    @Modar -- Yea we can do that. Not ideal, but may work. thanks for everyone's input – zas1220 Oct 22 '21 at 12:33

0 Answers0