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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:44+00:00 2026-05-28T06:58:44+00:00

I need to do authorization and auditing on some WCF service methods. I’d like

  • 0

I need to do authorization and auditing on some WCF service methods. I’d like to do the processing in an attribute to avoid polluting my code. I’ve created a custom attribute using PostSharp and am wondering if this is a suitable approach or if there are any gotchas with relying on PostSharp for authorization mechanisms given that it is tweaking the MSIL?

In my WCF service class I’m using the attribute in the manner below.

 [AuthoriseAndAudit(UserRoleTypesEnum.Operator)]
 public JSONResult<bool> IsAliveAuthorised()
 {
     return new JSONResult<bool>() { Success = true, Result = true };
 }

The abbreviated attribute code is as below.

using PostSharp.Aspects;

[Serializable]
public class AuthoriseAndAuditAttribute : OnMethodBoundaryAspect
{
    private static ILog logger = AppState.logger;

    private UserRoleTypesEnum _requiredRole = UserRoleTypesEnum.None;

    public AuthoriseAndAuditAttribute(UserRoleTypesEnum role = UserRoleTypesEnum.None)
    {
        _requiredRole = role;
    }

    public override void OnEntry(MethodExecutionArgs args)
    {
        logger.Debug(String.Format("AuthoriseAndAuditAttribute checking {0}.", args.Method.Name));

        // Get the user's session from cookie.
        UserSession userSession = GetUserSession();

        // Check that user is in the required role.
        bool isAuthorised = (_requiredRole == UserRoleTypesEnum.None || (userSession != null && userSession.Roles.Contains(_requiredRole)));

        // Write an audit table entry.
        logger.Debug("Writing audit table entry.");

        if (!isAuthorised)
        {
            logger.Warn("Not authorised for " + args.Method.Name + ".");
            throw new UnauthorizedAccessException();
        }
    }
}
  • 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-28T06:58:45+00:00Added an answer on May 28, 2026 at 6:58 am

    Normally I would say yes, but WCF has ways to do authorization so using PostSharp would be redundant and unnecessary work.

    If you need to implement a custom authorization setup then yes, PostSharp will greatly aid in that.

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

Sidebar

Related Questions

I need some help about WCF and authorization. Currently I have a client which
Need some help about with Memcache. I have created a class and want to
I need an attribute that handles authorization for my controllers. This is for a
I'm confused on ASP.NET MVC caching and authorization and in dire need of some
I'm working on a project where I need the following. WCF service on the
I need an authentication service and authorization service for c# desktop applications.
I need to use more complicated authorization, so I created class which can throw
I need to implement a very secured Web Service using WCF. I have read
I need to put custom headers into WCF. My Code is as follows: ServiceReference1.Service2Client
I need to validate a basic authorization header that is being sent to my

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.