简体   繁体   中英

Run a function just once in StartUp.cs After application Deployment

I am developing ASP.NET core 2.2 web application. I want to run a function just once after the application is deployed each time in Startup.cs file.

This function slows down the application as it does some heavy checks on the application startup. I only want to run this just once each time when the application is deployed.

This is the code


SynapseCore.Services.Plugins.SiteContentDiscovery iCont = new SiteContentDiscovery();
            _logger.LogInformation("Startup - Complete : SiteContentDiscovery", new object[0]);

            SynapseCore.Shared.GlobalData.pluginList = pluginsInfoList;
            _logger.LogInformation("Startup - Complete : pluginList", new object[0]);

            iCont.SetPluginInfo(pluginsInfoList);
            _logger.LogInformation("Startup - Complete : SetPluginInfo", new object[0]);

        //The following function 'CheckDatabaseIntegrity' is to be run once after deployment. 
           iCont.CheckDatabaseIntegrity();
          _logger.LogInformation("Startup - Complete : CheckDatabaseIntegrity", new object[0]);

            iCont.CheckPluginStatus();
            _logger.LogInformation("Startup - Complete : CheckPluginStatus", new object[0]);

            PluginSiteComposedData composedData = iCont.CompileSiteDataList();

I have looked into

Environment.GetEnvironmentVariables() 

But doesn't seem to have that attribute i am looking for.

My question is, how do i detect through code if the application is running for the first time after deployment on IIS ?

You could simply store and check the assembly version. If it increased you can assume that you deployed a new version.

But you also have to increase it in your project properties each time you want to deploy a new version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM