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 7982787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:46:33+00:00 2026-06-04T10:46:33+00:00

I am trying to create a Custom Attribute for a ServiceStack Service with which

  • 0

I am trying to create a Custom Attribute for a ServiceStack Service with which I can control each method in the service Class.

This is the attribute class that I am implementing.

[AttributeUsage(AttributeTargets.Method|AttributeTargets.Class , Inherited = false, AllowMultiple = false)]
public class MyRequestFilterAttribute:RequestFilterAttribute
{

    public string Provider { get; set; }

    public MyRequestFilterAttribute(ApplyTo applyTo): base(applyTo)
    {
        this.Priority = (int) RequestFilterPriority.Authenticate;
    }

    public MyRequestFilterAttribute():this(ApplyTo.All)
    {

    }

    public MyRequestFilterAttribute(ApplyTo applyTo, string provider): this(applyTo)
    {
        this.Provider = provider;
    }

    public MyRequestFilterAttribute(string provider): this(ApplyTo.All)
    {
        this.Provider = provider;
    }

    public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
    {}
}

This is the Service Class

[MyRequestFilter(ApplyTo.All)]
public class TodoService : RestServiceBase<Todo>
{
    public TodoRepository Repository { get; set; }                  
    public override object OnGet(Todo request)
    {
        if (request.Id == default(long))
            return Repository.GetAll();

        return Repository.GetById(request.Id);
    }
    public override object OnPost(Todo todo)
    {
        return Repository.Store(todo);
    }
    public override object OnPut(Todo todo)
    {
        return Repository.Store(todo);
    }
         [MyRequestFilter("Admin")]
    public override object OnDelete(Todo request)
    {
        Repository.DeleteById(request.Id);
        return null;
    }
    public object GetDetailsofALL()
    {
        return null;
    }
}

I am able to get control on the Methods when I place the attribute on the Class level.
i.e

[MyRequestFilter(ApplyTo.All)]
public class TodoService : RestServiceBase<Todo>{}

What I require is to place an attribute on the method level as well and do some authentication such that only an admin has the right to perform this method of the service.
But when I place this attribute in the Delete method it is not working and the custom filter attribute is not getting hit. Only the class level attribute call works.

[MyRequestFilter("Admin")]
public override object OnDelete(Todo request){}

Is it possible to set the permission/filter attribute from the method level? If yes, how can I implement 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-06-04T10:46:35+00:00Added an answer on June 4, 2026 at 10:46 am

    No it’s not possible to add it on the method. You can add it on the service class or the Request DTO and use the ApplyTo method filter to tell servicestack which methods it should apply to, e.g:

    [MyRequestFilter(ApplyTo.All)]
    [MyRequestFilter(ApplyTo.Delete, "Admin")]
    public class TodoService : RestServiceBase<Todo> { ... }
    

    You can also refer to the implementation of the [RequiredRole] and [RequestPermission] attributes for examples of Request Filter attributes that support this.

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

Sidebar

Related Questions

I'm trying to create a custom deployer in Tridion 2011 SP1 that can index
I was trying to create a custom attribute for logging (caller's class name, module
I'm trying to create a custom attribute for each list item in a databound
I'm trying to create a custom attribute that will work in a sort-of AOP
I'm trying to create a custom attribute to control formatting in a custom HTML
hi i am trying to create a custom attribute for my MVC application so
I'm trying to create a custom control (deriving from Control ) with its own
I'm trying to create a custom function in a model manager: class MessageManager(models.Manager): #
I was trying to create a custom combobox that inherited from ComboBox, but I've
I'm trying to create a custom class for my pages in my project. Here's

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.