I need to load some data before the first request in ASP.Net Web API. For example, immediately after deploy the ASP.Net Web API application starts and load some data.
How is it possible?
I need to load some data before the first request in ASP.Net Web API. For example, immediately after deploy the ASP.Net Web API application starts and load some data.
How is it possible?
One way would be to change the Application_Start method.
You can check this to see how it works : https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/configuring-aspnet-web-api
So, in the application start method, you do what you need, load the data that you want.
Now, assuming this data is supposed to be available to the application at all times, I would cache it.
Some ways of doing that can be explored here for example: How to manage cache in ASP.NET WebApi2?
I assume that this data that you want loaded is something which is not user specific which means that loading it in Application_Start, before any requests arrive will work just fine.