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 |
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.Web; | |
| using System.Web.Mvc; | |
| using System.Diagnostics; | |
| /// <summary> | |
| /// A simple attribute that times controller actions, returning the measured time | |
| /// in the HTTP header "X-Duration". | |
| /// </summary> |
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 LogAttribute : ActionFilterAttribute { | |
| private IDictionary<string, object> parameters; | |
| private string description; | |
| public LogAttribute(string description) { | |
| this.description = description; | |
| } | |
| public override void OnActionExecuting(ActionExecutingContext filterContext) { | |
| parameters = filterContext.ActionParameters; |