This file contains hidden or 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
| public class RequireApiKey : ActionFilterAttribute | |
| { | |
| private static readonly ILog Logger = LogManager.GetLogger(typeof(RequireApiKey)); | |
| public override void OnActionExecuting(HttpActionContext context) | |
| { | |
| var ipAddress = GetIpAddress(context); | |
| Logger.InfoFormat("API attempt. Uri {0} - IP {1} - Headers {2} ", context.Request.RequestUri, ipAddress, context.Request.Headers); | |
| IEnumerable<string> values; | |
| if (context.Request.Headers.TryGetValues("ApiKey", out values) && GetApiKeys().Any (x => x ==values.First()) |
This file contains hidden or 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 System; | |
| using System.Net; | |
| using System.Web.Mvc; | |
| using System.Web.Routing; | |
| namespace Web.Filters | |
| { | |
| /// <summary> | |
| /// Check whether the application is marked as offline in the config file. | |
| /// If so, and the user does not have the override permission, throw an exception. |
This file contains hidden or 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
| public class MinifyInlineScriptsAttribute : ActionFilterAttribute | |
| { | |
| public override void OnActionExecuting(ActionExecutingContext filterContext) | |
| { | |
| var originalFilter = filterContext.HttpContext.Response.Filter; | |
| if(originalFilter != null) filterContext.HttpContext.Response.Filter = new MinifyStream(originalFilter); | |
| base.OnActionExecuting(filterContext); | |
| } |
This file contains hidden or 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
| [Route("api/dothis/{id}")] | |
| [AcceptVerbs("POST")] | |
| [Throttle(Name = "ApiThrottle", Message = "You must wait {n} seconds before accessing this url again.", Seconds = 5)] | |
| [Authorize] | |
| public HttpResponseMessage DoThis(int id) | |
| { | |
| // do something | |
| } | |
| public class ThrottleAttribute : ActionFilterAttribute |
This file contains hidden or 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 System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using System.Linq; | |
| using System.Web; | |
| using System.Web.Mvc; | |
| using System.Web.Routing; | |
| namespace SampleAudit | |
| { |
This file contains hidden or 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 System.Web.Mvc; | |
| using System.Web.Routing; | |
| using System.Web.WebPages; | |
| namespace MyNamespace | |
| { | |
| public enum DeviceType {Mobile, Desktop} | |
| public class DeviceTypeRedirect : ActionFilterAttribute | |
| { |
This file contains hidden or 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 System.Web.Mvc; | |
| namespace MvcApplication1.Models | |
| { | |
| public class CheckBrowserAttribute : ActionFilterAttribute | |
| { | |
| public override void OnActionExecuted(ActionExecutedContext filterContext) | |
| { | |
| base.OnActionExecuted(filterContext); | |
| } |
This file contains hidden or 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
| public class WordDocumentAttribute : ActionFilterAttribute | |
| { | |
| public string DefaultFilename { get; set; } | |
| public override void OnActionExecuted(ActionExecutedContext filterContext) | |
| { | |
| var result = filterContext.Result as ViewResult; | |
| if (result != null) | |
| result.MasterName = "~/Views/Shared/_LayoutWord.cshtml"; |
This file contains hidden or 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
| public class LogActionWebApiFilter : ActionFilterAttribute | |
| { | |
| /// <summary> | |
| /// Instance of the Log4Net log. | |
| /// </summary> | |
| [Dependency] //Part 1 | |
| public ILog Log { get; set; } | |
| //This function will execute before the web api controller | |
| //Part 2 |
This file contains hidden or 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 System; | |
| using System.Net.Http; | |
| using System.Net.Http.Formatting; | |
| using System.Web.Http.Filters; | |
| using Newtonsoft.Json.Serialization; | |
| namespace Filters | |
| { | |
| [AttributeUsage(AttributeTargets.All)] | |
| public class CamelCasingFilterAttribute : ActionFilterAttribute |