简体   繁体   中英

Determine if code changed in C#

We have an ASP.NET MVC website in C#, and when they publish new code, they don't usually restart the web server. This can cause problems because some code changes might assume that new code called in App_Start fired, or some lookup values in static variables might be outdated relative to code changes.

What I'm thinking of doing to solve this problem is to have a static variable set to AssemblyName.Version. Then on any web request, I would have code check AssemblyName.Version against the static variable, and if it's different, it would update that static variable and run certain code to refresh caches and perform certain tasks that would normally be run by App_Start.

What I'm wondering is whether there's any better way of handling this. Surely this is a common situation, so I'd be curious how others are handling this.

Put the version number or something unique in the web.config file. This will trigger ASP.NET runtime to restart the application. You do not need to do nothing with it, so long as it is there and it is different from the previous web.config , it will do the job.

But I still think you should tell your deployment to get their act together; you cannot babysit them. If their job is to deploy, they should know how to do it. Forgetfulness is not a good reason.

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