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

  • Home
  • SEARCH
  • 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 3623382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:22:35+00:00 2026-05-18T23:22:35+00:00

I am attempting to build a system that allows users to perform certain actions,

  • 0

I am attempting to build a system that allows users to perform certain actions, but their account must have a specific ‘Ticket’ per time they do it. For instance, suppose they wish to create a Product, they would need a CreateProductTicket.

I could simply do this with some ‘if’ statements, sure, but I want to try a bit more of a robust solution. My structure looks something like this…

interface ITicket<T> where T : ITicketable
{
}

My basic goal is to build an Attribute, perhaps like the following..

public class TicketRequiredAttribute : Attribute
{
 public TicketRequiredAttribute(ITicket<T> ticket)
 {
  if(ticket == null) 
    return;
  }
}

And to be able to decorate Controller or Repository Actions with this. So like …

ProductsControlller

[TicketRequired(CreateProductTicket)]
public ActionResult CreateProduct(Product product)
{
 // ... **I am unsure how to tell if TicketRequired was true or not**
}

Problem 1

I’m not familiar enough with attributes to know how to tell if TicketRequired was ‘met’ or not. Can anyone enlighten me on this?

Problem 2

The problem I am running into is with database querying. I want to be able to check the user (IMembershipRepository has a GetUser method), but I’m not entirely certain how to do that through an attribute.

Using Castle.Windsor, I have my Dependency Injection set up to inject repositories into controllers. I suppose I could pass the IMembershipRepository through the TicketRequired constructor, but I have a feeling that will become very messy – and extremely unstable. Is there a more logical way to approach this?

  • 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-18T23:22:36+00:00Added an answer on May 18, 2026 at 11:22 pm

    You’re almost there. You can find more details at http://www.asp.net/mvc/tutorials/understanding-action-filters-cs

    I would only use the attribute on the action since the website is where I do all my authorization.

    Here is a possible solution. I have not tested this, but it should work. You’ll need to verify the way I’m redirecting, not sure if that’s the proper way.

     public class TicketRequiredActionFilter : ActionFilterAttribute
     {
            private Type _ticketType;
    
      public TicketRequiredAttribute(Type ticketType)
      {
            _ticketRequired = ticketType;     
      }
    
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
         UserServices userServices = GetUserServicesViaDIContainer(); // you'll need to figure out how to implement this 
         string userId = filterContext.HttpContext.User.Identity.Name
         bool hasTicket = userServices.HasTicket(_ticketType, (int)userId); // again, you'll need to figure out the exact implementation
         if(!hasTicket)
         {
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, {"action", "NoPermission" } })
         }
         else
         { 
            base.OnActionExecuting(filterContext);
         }     
      }
    }
    

    In your controller:

    [TicketRequiredActionFilter(typeof(CreateProductTicket))]
    public ActionResult MyMethod()
    {
        // do stuff as if the person is authorized and has the ticket
    }
    

    If the user doesn’t have the ticket, a redirect is issues;, otherwise, continue as normal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a caching system build within php that stores the results of a
I am attempting to build a simple method that creates an XML file from
I'm trying to build a modified role system that has the following class/relationship structure:
I am attempting to build a particle system utilizing CUDA to do the heavy
Hopefully some Custom Control Designers/Builders can help I'm attempting to build my first custom
Context: So, I am attempting to build a ridiculously complex domain model. Talking with
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
Attempting to print out a list of values from 2 different variables that are
I'm trying to build a proof of concept Csla 3.7/Silverlight 3 app and have
I am attempting to a get a isolated build environment setup in my dev

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.