actionfilterattribute

ASP.Net MVC ignoring filter order...

Hi guys Just wondering if anyone has any idea of why my filter order is being ignored... [AcceptVerbs(HttpVerbs.Get)] [Compress(Order = 1)] [EnhancedOutputCache(Order = 2, Duration = 5, VaryByParam = "true", Location = OutputCacheLocation.ServerAndClient)] public virtual ActionResult Index() { return View(); } public class Compr...

ViewData in ActionFilterAttribute - Object reference not set to an instance of an object.

Hello all, I've been trying to load masterpage content from database (based on a "TargetCode" in the querystring), using ActionFilterAttribute. However, I'm having problem setting the ViewData to the data returned from the database, here is the code: public override void OnActionExecuting(ActionExecutingContext filterContext) { Ho...

ASP.NET MVC - ActionFilterAttribute to validate POST data

Hello there, Actually I have an application that is using a WebService to retrieve some clients information. So I was validating the login information inside my ActionResult like: [AcceptVerbs(HttpVerbs.Post)] public ActionResult ClientLogin(FormCollection collection) { if(Client.validate(collection["username"], collection["passwor...

Detecting redirect in IActionFilter.OnActionExecuted reliably

I have an IActionFilter that does something in OnActionExecuted, however I don't want to perform this action when the controller result performs a redirect. My initial thought was to check the type of the ActionResult as either RedirectResult or RedirectToRouteResult, but this isn't reliable as any type of result can perform a redirect ...

Flushing and Compression filters (ASP.NET MVC)

We have quite common code which worked fine: public class CompressionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; if (request.IsAjaxRequest(...

ASP.Net MVC Error handling using Action Filters Attributes

I am trying to implement Error handling using Action Filters Attributes as per ScottGu's blog My code is as follows: [HandleError] [HandleError(ExceptionType = typeof(NullReferenceException), View = "CustomError")] public class ArticlesController : Controller { public object OhDearACrash() { throw new Exception("Oh Dear...

ASP.Net MVC Custom Error handling via Action Filter Attributes

I am trying to implement Custom Error handling via Action Filter Attributes. My code is as follows: [HandleError (Order = 2)] [HandleError (Order = 1, ExceptionType = typeof(NullReferenceException), View = "CustomError")] public class ArticlesController : Controller { public object OhDearACrash() { throw new Exception(...

Action Filter ActionParameters

I have an ActionFilterAttribute which I want to accept parameters through but I can't figure out pass them across. So my action filter looks like this; public class PreventAction : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.Result = new RedirectRe...

ActionFilterAttribute: Where is the 'Cancel' property?

Whatever happened to the Cancel property on the ActionExecutingContext? How would one abort a RenderAction when using an ActionFilterAttribute or is there another way to skin this cat? public override void OnActionExecuting(ActionExecutingContext filterContext) { if(!filterContext.HttpContext.User.Identity.IsAuthenticated) { ...

Ninject 2 Property Injection for ActionFilterAttribute not working

I have a method attribute which expects several properties to be injected by Ninject 2, but userSession and jobRepository are coming up as null: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class JobAttribute : ActionFilterAttribute { [Inject] private IUserSession userSession; [Inject] private...

Stop continuation of ASP.NET MVC ActionFilter

I have two custom ActionFilters on an action. In first of the actionfilters, I have an redirect performed if a condition is not met (classic authorization). And in another I have an redirect performed if another condition is not met (say role checking). But I do not want to continue to the second actionFilter if the first one is not ...

Localize DisplayNameAttributes in ActionFilter?

Is it possible to access the DisplayNameAttributes that are used on my ViewData.Model so I can Localize them before sending them to the view? Something like this: Public Void OnActionExecuted(ActionExecutedContext: filterContext) { foreach (DisplayNameAttribute attr in filterContext...) { attr.TheValue = AppMessages.GetLocazation(...

What is the order of execution when dealing with .NET MVC 2 Action Filters?

Say I have: [Attribute1(Order=0)] public class Controller1 { [Attribute2] [Attribute3] public ActionResult Action1() { ... } } The attributes get executed in the following order: 2, 3, 1 This makes sense because attributes 2 and 3 have an order of -1 and will be executed before attribute 1 which has an explici...

Why does my ActionFilterAttribute redirect after the action code is run?

I'm trying to use a ActionFilterAttribute to redirect users that are not logged in. Although my redirect is working it redirects but it calls all of my ActionResult code first. Any ideas as to why it doesn't honour the true flag and end the response? HttpContext.Current.Response.Redirect("~/Logon",true); Here is my ActionResult: [Re...

ASP.NET MVC - Filter which action to invoke based on the query string

Hi, i was wondering if it was possible to filter which action is invoked based on a paramater in the query string. For example, i have a grid with a radio button column to select an item in the grid. The grid is wrapped in a form and at the top of the grid are buttons to edit/delete the selected item. Clicking on the edit/delete butto...

Hide/Show content using ActionFilterAttribute/AuthorizeAttribute

I'm using MVC 2 with futures, and I'm trying to hide/show content based on role. Is there a way with ActionFilterAttribute or AuthorizeAttribute if the authentication fails to not show the controller child action all through attributes? Or is all I can do with those attributes is redirect or throw up an error message? I just need the ...

How to automatically overload DELETE and PUT if they are not available by the client?

How can I detect at the startup of the application that a client doesn't support DELETE and PUT verbs and automatically overload the POST verb? On the server side, how can I redirect those overloaded POST verbs into the right actions? Say I have a DELETE request that is overriden, how do I call the appropriate function in the controller ...

ASP.NET MVC action filters: Setting the filterContext.Result in a filter prevents other filters from being executed?

I currently have 2 filters, Auth and Redirect that do the following: Filter Auth, who implements IAuthorizationFilter and ActionFilter, checks for user login and authorization, and if that fails sets the filterContext.Result to be a HttpStatusCodeResult of 403 (forbidden). Filter Redirect, who implements IActionFilter and ActionFilter, ...