Created
August 24, 2012 07:02
-
-
Save amitapl/3446947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAzure.MobileServices; | |
using System; | |
using Windows.Foundation; | |
namespace MobileServices | |
{ | |
public class AdminServiceFilter : IServiceFilter | |
{ | |
private bool disableScripts; | |
public AdminServiceFilter(bool disableScripts) | |
{ | |
this.disableScripts = disableScripts; | |
} | |
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) | |
{ | |
// Add master key to the request's header to have admin level control | |
request.Headers["X-ZUMO-MASTER"] = "Your Master Key Here"; | |
if (this.disableScripts) | |
{ | |
// Get the request's query and append noScript=true as the first query parameter | |
var uriBuilder = new UriBuilder(request.Uri); | |
var oldQuery = (uriBuilder.Query ?? string.Empty).Trim('?'); | |
uriBuilder.Query = ("noScript=true&" + oldQuery).Trim('&'); | |
request.Uri = uriBuilder.Uri; | |
} | |
return continuation.Handle(request); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment