0
votes

I am using the azure-mobile-apps-net-server SDK for my smartphone app backend. Now I want to show the smartphone user some message, when there is a new update available. My idea is to include the current version number of the smartphone app in the header of the request, which goes to the backend.

Now I can read the version in the backend, compare it to some value and throw an HttpResponseException, which the client will catch. Then I can show the client user some message to update to a newer version.

Here some pseudocode:

public void ValidateClientVersion()
{
  var version = request.header["X-Client-Version"];
  if (version != 3.2.1)
    throw new HttpResponseException(...);
 }

Now my problem I have multiple Actions in multiple TableControllers. I think there must be some very simple way to call ValidateClientVersion() before any of the Actions is called. I don't want to add the method call in every single Create, Update, Delete, ... Action.

However as I am new to ASP.Net? or what ever the azure-mobile-apps-net-server Framework is called, I don't know this simple solution.

Can someone point me in the right direction?

2
If you are using asp.net mvc then Action filters is what you are looking for asp.net/mvc/overview/older-versions-1/controllers-and-routing/… - Mitul

2 Answers

1
votes

It's probably a bad idea to do this over every single version. Your better bet from a user experience perspective is to create a simple WebAPI in your mobile backend that returns the current version, potentially with a download link (based on the OS of the connecting mobile app).

When your mobile app connects, it first calls the WebAPI. If the WebAPI has a different version, then pop up the message and the download link and exit.

This is similar to what we suggest for offline sync schema changes. If the schema version changes, wipe the offline sync SQLite and re-sync.

0
votes

If you really want do do that you can create a subclass of ApiController, lets call it MyController and make your controllers all derive from it.

Then override the ExecuteAsync function in MyController, put your logic there and end the function with return await base.ExecuteAsync(controllerContext, cancellationToken); so it continues to execute the code in your controller.