I'm writing a new asp.net mvc application and I've been toying with the idea of allowing my user to post short, concise urls to content that he has posted. Those short url's will be handy in cramped spaces like Twitter and comment areas. I like this idea as I'm not a huge fan of url shorteners because they're so vague and you're never re...
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(...
If you have a model-bound parameter in an action method, how can you get to that parameter in an action filter?
[MyActionFilter]
public ActionResult Edit(Car myCar)
{
...
}
public class MyActionFilterAttribute : ActionFilterAttribute
{
public void OnActionExecuted(ActionExecutedContext filterContext)
{
//I want to a...
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...
I have a custom filter attribute that I want to use on certain ActionResults to look at the data being attempted and to set values where certain rules are violated.
So;
public class SpecialActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
foreach (strin...
Hi, I would like to secure my MVC controller actions using...
[PrincipalPermission(SecurityAction.Demand, Role="Administrator")]
However, if the user is not in this role then a SecurityException "Request for principal permission failed." is thrown by the code.
There seems to be no way to handle this error, even [Handle] error wont ca...
Hello,
I have an actionfilter that I am running OnActionExecuting in ASP.NET MVC 2. Essentially I would like the actionfilter to sanitize my data and replace the current model (which will be passed to subsequent action filters and also my action method) with the sanitized model. Is this possible and is it a bad idea - if so why?
Thank y...
A well-known benefit of MVC is its suitablility for Test Driven Development (TDD) because you can directly call your controller actions from your test methods.
How can you test the combination of a controller action with a ActionFilter attribute (using OnActionExecuted to modify the ActionResult returned by the Action)? If I just call ...
Please help me with this action filter.
I think i need to use OnResultExecuted method
How can i have access to otput html and replace something in them?
thank you.
...
I am using an ActionFilter (see below) to detect whether or not 1. the current controller/action requires SSL and 2. SSL is currently being used, and redirect accordingly.
This works fine locally (using a dummy cert in IIS 7) but once I get it up on the server I get an error indicating an infinite redirect loop.
Any ideas?
public cla...
I cache everything that is possible on an ASP.NET MVC website and it works perfect. Now I have created an API where the calls go to Controller Actions. (http://mysite.com/topics/latest.json)
The API is able to return results in different formats (json, xml, rss).
The data for returning is loaded in the Action:
[ResponseFilter]
public ...
In a custom ActionFilter, I want check the attributes on the controller action that will be executed. Running through a small test application, the following works when launching the app in the asp.net development server-
public class CustomActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(Action...
I want to create a action filter that will check the url, and if its not using Ssl, redirect to the same page but with SSL.
What is the best way of doing this?
Should I just check the RawUrl, and scan the string for https, and if its not there then do:
context.Response.Redirect(context.Request.RawUrl.Replace("http:", "https:"));
...
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating. I have an action which accepts an Http Post and the argument of the action method accepts an object, for which I have created and registered a custom model binder.
I noticed that inside the IActionFilter.OnActionExecuting the value for filterContext.Cont...
I'm trying to output to Trace.axd from an ASP.NET MVC app. I have traces in OnActionExecuting(), OnActionExecuted(), OnResultExecuting() and OnResultExecuted() and all of them output to Trace.axd except for OnResultExecuted().
For completeness' sake here's my code (exactly the same for OnActionX() ):
protected override void OnResu...
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 ...
Say I have a controller called "HomeController" which inherits from Mvc.Controller. Also say I have written the constructor of the controller and some filters for some actions.
Public Class ClientController
Inherits System.Web.Mvc.Controller
Public Sub New()
''Some code
End Sub
<SomeActionFilter()> _
Functi...
I recently built a site using Asp.Net.
The way I chose to implement user login is through a base 'UserAwareController' class, that all controllers extend. It contained a reference to the UserRepository, and exposed a protected GetCurrentUser() method that concrete controllers could query.
The whole process felt a bit wishy-washy to me....
As suggested by (among others) Kazi Manzur Rashid in this blog post, I am using ActionFilterAttributes to transfer model state from one request to another when redirecting.
However, I find myself unable to write a unit test that test the behavior of these attributes. As an example, this what I want the test for the ImportModelStateAttri...
In ASP.NET MVC 2, a couple of new action filter attributes were introduced, as "shorthand" for attributes in ASP.NET MVC 1; for example, applying the HttpPostAttribute does the same thing as applying [AcceptVerbs(HttpVerbs.Post)] to an action method.
In addition, with the more verbose syntax, it is possible to combine different methods,...