custom-action-filter

Refresh OutputCache Profile on Demand

天涯浪子 提交于 2021-01-29 15:20:30
问题 I am using an OutputCache Profile to cache on the server some json data. [HttpGet] [OutputCache(CacheProfile = "1HourCacheProfile")] public JsonResult GetBranches() { var result = mMapper.Map<List<IntItem>>(mConfigurationServices.GetBranches()); return Json(new { list = result }, JsonRequestBehavior.AllowGet); } The profile is registered in Web.config as below I want to hook somehow a refresh logic on this cached output on different actions that are updating my source. I have found some

Asp.Net MVC 5 Custom Action Filter With StructureMap

青春壹個敷衍的年華 提交于 2020-01-13 12:08:15
问题 i am facing issue in asp.net mvc custom acitonfilte using structuremap in my "LogAttribute" class i have setter dependency injection which is coming null when executing the "OnActionExecuted" Method of my customfilterclass which is "LogAttribute" my LogAttribute Class code is public class LogAttribute : ActionFilterAttribute { public ApplicationDbContext Context { get; set; } public string Description { get; set; } public LogAttribute(string description) { Description = description; } public

ASP.NET MVC 3 Custom Action Filter - How to add incoming model to TempData?

青春壹個敷衍的年華 提交于 2020-01-01 16:10:29
问题 I'm trying to build a custom action filter which grabs the incoming model out of the filter context, adds it to tempdata, then does "other stuff". My action method looks like this: [HttpPost] [MyCustomAttribute] public ActionResult Create(MyViewModel model) { // snip for brevity... } Now, i want to add the model to TempData , after the model-binding has kicked in and transformed the form value collection into MyViewModel . How do i do that? public override void OnActionExecuting

How do I add a parameter to an action filter in asp.net?

折月煮酒 提交于 2019-12-29 05:16:05
问题 I have the following filter attribute, and i can pass an array of strings to the attribute like this [MyAttribute("string1", "string2")] . public class MyAttribute : TypeFilterAttribute { private readonly string[] _ids; public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { _ids = ids; } private class MyAttributeImpl : IActionFilter { private readonly ILogger _logger; public MyAttributeImpl(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<MyAttribute>();

How do I add a parameter to an action filter in asp.net?

老子叫甜甜 提交于 2019-12-29 05:16:04
问题 I have the following filter attribute, and i can pass an array of strings to the attribute like this [MyAttribute("string1", "string2")] . public class MyAttribute : TypeFilterAttribute { private readonly string[] _ids; public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { _ids = ids; } private class MyAttributeImpl : IActionFilter { private readonly ILogger _logger; public MyAttributeImpl(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<MyAttribute>();

ASP.NET MVC - CustomeAuthorize filter action using an external website for loggin in the user

此生再无相见时 提交于 2019-11-29 02:20:01
I have a CustomeAuthorize action filter that forwards the user to signin page if user is not authenticated. I apply this filter to actions or controllers. [CustumeAuthorize] public ActionResult MyAction() { //do something here return View(); } and the filter looks like this: public class CustomAuthorizeAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!currentUserIsAuthenticated) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary{{ "controller", "Account" }, { "action", "SignIn" }, { "returnUrl",

How do I add a parameter to an action filter in asp.net?

本秂侑毒 提交于 2019-11-29 01:25:20
I have the following filter attribute, and i can pass an array of strings to the attribute like this [MyAttribute("string1", "string2")] . public class MyAttribute : TypeFilterAttribute { private readonly string[] _ids; public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { _ids = ids; } private class MyAttributeImpl : IActionFilter { private readonly ILogger _logger; public MyAttributeImpl(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<MyAttribute>(); } public void OnActionExecuting(ActionExecutingContext context) { // HOW DO I ACCESS THE IDs VARIABLE

Asp.net mvc - Accessing view Model from a custom Action filter

匆匆过客 提交于 2019-11-28 06:14:33
I am trying to access the Model data passed to the view in the action filter OnActionExecuted. Does anyone know if this is possible? I am trying to do something like this: public override void OnActionExecuted(ActionExecutedContext filterContext) { //get model data //... sitemap.SetCurrentNode(model.Name); } Any advice? The model is at: filterContext.Controller.ViewData.Model gustavocs I don't know why but filterContext.Controller.ViewData.Model is always null even when the model bind is executed before OnActionExecuted . I found a solution using the OnModelUpdated event to set that property

ASP.NET MVC - CustomeAuthorize filter action using an external website for loggin in the user

纵然是瞬间 提交于 2019-11-27 16:39:47
问题 I have a CustomeAuthorize action filter that forwards the user to signin page if user is not authenticated. I apply this filter to actions or controllers. [CustumeAuthorize] public ActionResult MyAction() { //do something here return View(); } and the filter looks like this: public class CustomAuthorizeAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!currentUserIsAuthenticated) { filterContext.Result = new

Asp.net mvc - Accessing view Model from a custom Action filter

谁说我不能喝 提交于 2019-11-27 01:13:56
问题 I am trying to access the Model data passed to the view in the action filter OnActionExecuted. Does anyone know if this is possible? I am trying to do something like this: public override void OnActionExecuted(ActionExecutedContext filterContext) { //get model data //... sitemap.SetCurrentNode(model.Name); } Any advice? 回答1: The model is at: filterContext.Controller.ViewData.Model 回答2: I don't know why but filterContext.Controller.ViewData.Model is always null even when the model bind is