0

Hy everybody,

i developed an ASP.NET Core 3.1 (soon .NET 6) Web Application which is connected to an ATM-API. The ATM-API requires that i hold static variables at the server. Unfortunately the objects are not serializeable.
The App is hosted on IIS 10 on a Windows Server 2019. I know that the static variables get lost, when e.g. the Application Pool recycles.

But the static variables should not get lost. Now i am thinking about possible Solutions and i don´t know, which way i should go.

These Solutions came into my mind:

  1. Write a Windows Service where i hold the static variables and call it (somehow) from my ASP.NET Core App.
  2. Preventing the Application Pool from recycling at least during the Service-Time 7:30 to 18:00. I researched for this solution but it looks like that i cant fully prevent it. But maybe i don´t found the solution yet.

Maybe someone of you has a great idea :-). Thank you very much :-).

6
  • You can also write an encrypted string to disk and read it on startup. At what point are the static variables invalid though? You want to let the app pools recycle, since there might be a leaky DLL or even your own code. Depending if you want to go that far, there are secrets managers out there that will store/encrypt your secret stuff... Build a lightweight web api service to store it somewhere else, lots of things to choose from. Commented Oct 5, 2022 at 20:36
  • Hi, the static variables (objects) are invalid (because null) after pool recycling. every cashier has to do an login when he starts using the atm and after the pool recylce the connection from the system to the atm is lost so they have to login again. That is not that hard because that happens maybe 2-3 Times per Week, but it is annoying for the cashier. I will research your suggestions. Thank you very much for your response :-). Commented Oct 6, 2022 at 5:55
  • If you want to persist static variables across your application life time, you can try to store the static variables in a DB. Commented Oct 6, 2022 at 8:56
  • I tried this first but unfortunately this Class is from a third party library and it is not serializable. I tried it with BinaryFormatter and XmlSerializer but i got in both ways an exception. That would be my favorite solution. Thank you for your input. Commented Oct 6, 2022 at 10:27
  • As far as I know, there doesn't seem to be any other way. Commented Oct 7, 2022 at 6:05

1 Answer 1

1

Maybe somebody is interested at my Solution:

After research i have decided to create a second ASP.NET Core App which i host as a Windows Service (https://www.thecodebuzz.com/host-asp-net-core-api-as-windows-services/). Because the Windows Service normally should run as long as the Windows-Server is up. When the Windows-Server restarts the Main-App is also not available and the Terminals are not needed.

Now all ATM-Objects are hold in the Windows Service and i call the Endpoints from my ASP.NET Core App which is hosted in IIS.

I also thought about to run my Main-App as Windows Service, but i am not aware about possible downsides when i Host it as Windows Service. I will research that later.

Thank you everybody for your Suggestions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.