Ejemplo n.º 1
0
        public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            // Don't process "snapshot" requests against a snapshot database
            if (context.Controller is SnapshotsController)
            {
                return(next());
            }

            if (context.HttpContext.Request.Headers.TryGetValue(SnapshotIdentifierHeaderName, out StringValues values))
            {
                // Ensure attempts to modify the snapshot are prevented
                if (!context.HttpContext.Request.Method.EqualsIgnoreCase(HttpMethod.Get.ToString()) &&
                    !context.HttpContext.Request.Method.EqualsIgnoreCase(HttpMethod.Options.ToString()))
                {
                    context.Result = new SnapshotsAreReadOnlyResult();
                    return(Task.CompletedTask);
                }

                _snapshotContextProvider.SetSnapshotContext(
                    new SnapshotContext(values.FirstOrDefault()));
            }

            return(next());
        }