public void OnActionExecuting(ActionExecutingContext filterContext) { var format = filterContext.HttpContext.Request.Query["format"]; switch (format) { case "json": RequestedType = FormatResponseType.Json; break; case "xml": RequestedType = FormatResponseType.Xml; break; default: RequestedType = FormatResponseType.Unknown; break; } }
public void OnActionExecuting(ActionExecutingContext filterContext) { var _contentType = filterContext.HttpContext.Request.Headers["Accept"]; switch (_contentType) { case string s when(s.Contains("application/json")): _requestedType = FormatResponseType.Json; break; case string e when(e.Contains("/xml")): _requestedType = FormatResponseType.Xml; break; default: throw new ArgumentException("Unknown Accept Type - dont know how to handle: " + _contentType); } }