0

The high level problem I'm trying to solve:

Given our design of
- c# web api to modify entities and retrieve view models
- react SPA frontend

I want to be able to conditionally turn the c# web api "off" and tell the SPA the "site is down for maintenance". The purpose for this is to prevent odd errors in the client in the case someone is using the site during the transition.

The initial idea I had to solve this was to wrap each call in a web.config check to see if the site is down, and if so, return a hard-coded error response which the frontend knows what to do with. However the cleanest approach I can think of is to inject a service into each web api controller and invoke it at the beginning of each route. I was instead hoping for a way to avoid this boilerplate.

In node I would decorate all the routes in a wrapper function that does this. C# is a little more foreign to me.

aaaaaa
  • 1,233
  • 13
  • 24
  • 1
    Possible duplicate of https://stackoverflow.com/questions/912142/put-a-website-in-maintenance-mode – gunr2171 Oct 26 '17 at 20:35
  • The solution is definitely the same. Seems closing this as a duplicate is the correct way to go per meta stackexchange. – aaaaaa Oct 26 '17 at 20:57

1 Answers1

2

If you host your WebAPI as its own ASP.NET site then you can place an app_offline.htm file in the IIS root, and it will automatically go into maintenance mode.

ASP.NET will immediately server 503's and the page contents for all new requests, while allowing existing requests to complete.

STW
  • 44,917
  • 17
  • 105
  • 161
  • I'm not sure what you mean by "host your WebAPI as its own ASP.NET site", forgive my lack of .NET knowledge. Right now we just have the frontend assets (index.html, js, css, etc) being statically served by IIS. I don't know ASP.NET has any part, it just seemed to be the appropriate tag for web api 2 – aaaaaa Oct 26 '17 at 20:38
  • that's a pretty fundamental topic. IIS uses ASP.NET to host/run .NET sites, including WebForms, MVC, WebAPI, etc – STW Oct 26 '17 at 20:40
  • Gotcha - this may work just fine then. I'll test it now. My limited understanding of ASP was that it encompassed the server side rendering of pages e.g. classic asp and mvc. I didn't realize it also encompassed web api. – aaaaaa Oct 26 '17 at 20:41
  • Works great. Thanks so much for your time – aaaaaa Oct 26 '17 at 20:49