controller-action

Enforce Action Filter on all Controller Actions (C# / ASP.NET MVC)

Hello, I made a new action filter (attribute, similar to [Authorize]) which authorizes access to a controller action based on a session value. However, I'm basically decorating all my controller actions with that attribute (with the exception of very few). So, I thought it would be better to have that Action Filter always executed exc...

[asp.net mvc] Using a filter to execute a different action?

I want to avoid having lots of if Request.IsAjaxRequest() in my controllers. I was thinking that if I could condense this logic to an ActionFilter it would be easy to adopt a convention in my application to provide a second action for any request that may use Ajax, while providing a fall back if JavaScript is disabled. public ActionRes...

How to use Custom AuthorizeAttribute for controller utilizing parameter value?

I am trying to secure a controller action to prevent a user from accessing an Entity that they do not have access to. I am able to do this with the following code. public ActionResult Entity(string entityCode) { if (CurrentUser.VerifyEntityPermission(entityCode)) { //populate viewModel... ...

Using a .NET MVC Controller Action as the Source for an HTML <img>

I'm trying to display the picture associated with a user in my database (the picture field's data type is image) on a page - unfortunately the code below fails to do that. HTML <img src="/User/Picture/1" /> Controller Action public byte[] Picture(int id){ UserRepository r = new UserRepository(); return r.Single(id).logo.ToAr...

How to support multiple forms that target the same Create action on the same page?

I want to have two separate forms on a single create page and one action in the controller for each form. In the view: <% using (Html.BeginForm()) { %> // Contents of the first (EditorFor(Model.Product) form. <input type="submit" /> <% } %> <% using (Html.BeginForm()) { %> // Contents of the second (generic input) form. ...

After calling URL "/article/1234abcd" how to retrieve the value `1234abcd` from inside the `article` action?

@RequestMapping(value = "/article", method = RequestMethod.GET) public final String article(final ModelMap model) { } If this is called using the address: /article/1234abcd How can the value 1234abcd be retrieved from inside the article method? ...