Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:22:14+00:00 2026-05-31T03:22:14+00:00

I am currently developing an ASP.NET MVC project. I want to implement an ActionFilter,

  • 0

I am currently developing an ASP.NET MVC project.

I want to implement an ActionFilter, that takes care about ownership permissions. A user may only access entities with which he is associated in the database.

Now I do not want to implement this into every Controller. Instead I want to use an ActionFilter.
I can already identify incoming parameters and read their values with the following code:

Controller

[Validate(ParameterName = "userID", EntityType="User")]
public ActionMethod Edit(int userID){...

ActionFilter

public string ParameterName { get; set; }
public string EntityType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
    if (EntityType != null && ParameterName != null)
    {
        Debug.Print("Checking if user has access to the Type \"" + EntityType + "\" with the
ID " + filterContext.ActionParameters[ParameterName]);
...

So far, this works fine. But when it comes to non-primitive types (e.g. User), I only find a NULL value in filterContext.ActionParameters[ParameterName]);

See

[HttpPost]
[Validate(ParameterName = "user", EntityType = "User")]
public ActionResult Edit(User user)
{....

I cant figure out why. Could it be because this is a HttpPost method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:22:16+00:00Added an answer on May 31, 2026 at 3:22 am

    This should work assuming you have derived from ActionFilterAttribute and haven’t implemented IAuthorizationFilter because if you implement this interface the action filter will run before the model binder and you will not be able to get the result of this model binder, only simple HTTP request values. Here’s an example:

    public class User
    {
        public string FirstName { get; set; }
    }
    

    Validation attribute:

    public class ValidateAttribute : ActionFilterAttribute
    {
        public string ParameterName { get; set; }
    
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var result = (User)filterContext.ActionParameters[ParameterName];
            if (result.FirstName == "john")
            {
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new User
            {
                FirstName = "john"
            });
        }
    
        [HttpPost]
        [Validate(ParameterName = "user")]
        public ActionResult Index(User user)
        {
            return View(user);
        }
    }
    

    View:

    @model User
    
    @using (Html.BeginForm())
    {
        @Html.EditorFor(x => x.FirstName)
        <button type="submit">OK</button>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are developing an ASP.NET MVC Application that currently uses it's own database ApplicationData
Currently in the early stages of developing a very large project using ASP.Net MVC.
Hello i am currently developing a ASP.NET MVC 3 application that uses the new
I'm currently developing a website in ASP .NET MVC and I require functionality for
I am currently developing an MVC application in ASP.net. I am using AJAX.ActionLink to
I'm currently developing an ASP.NET MVC application with a ton of PK-FK relationships in
I am currently developing an ASP.NET MVC 3 site using Visual Studio 2010 with
We are currently developing a web application in ASP.NET MVC which would really benefit
For the web application (ASP.NET MVC) I'm currently developing, we have the following architecture
I have an ASP.NET MVC application that I'm working on. I've been developing it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.