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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:05:20+00:00 2026-05-16T03:05:20+00:00

For my WCF services I’ve implemented an IAuthorizationPolicy and hooked it up (and can

  • 0

For my WCF services I’ve implemented an IAuthorizationPolicy and hooked it up (and can confirm that it’s being used).

In the Evaluate() method I am setting a custom principal like so:

evaluationContext.Properties["Principal"] = myCustomPrincipal;

However, when the service is invoked, Thread.CurrentPrincipal is a GenericPrincipal!

My service behavior is configured as follows:

<serviceAuthorization principalPermissionMode="Custom">
    <authorizationPolicies>
        <add policyType="MyNamespace.MyPrincipalAuthorizationPolicy, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </authorizationPolicies>
</serviceAuthorization>

I tried to use reflector to see what was going on but didn’t see anything useful.

Am I doing it wrong? Is there some configuration I’m missing?

  • 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-16T03:05:21+00:00Added an answer on May 16, 2026 at 3:05 am

    I’m not surprised there were tumbleweeds rolling around this question. There is nothing wrong with the approach I detailed in the question.

    It turns out the problem was that I was using a custom IInstanceProvider (I didn’t even think to include that information). If I stop using the custom instance provider everything works fine. But that’s no good as I still want to use it.

    So I found the only solution was to manually set the thread’s current principal inside the instance provider.

    The trick was getting hold of the principal I had set in the IAuthorizationPolicy – I managed to find it in the end using a rather cumbersome call via the static OperationContext.Current.

    public object GetInstance(InstanceContext instanceContext, Message message)
    {
        var principal =
            OperationContext.Current.ServiceSecurityContext.AuthorizationContext.Properties["Principal"] 
                as MyPrincipal;
        if (principal != null)
            Thread.CurrentPrincipal = principal;
        return ObjectFactory.GetInstance(_serviceType);
    }
    

    Of course, I’d be interested to know if there is a more elegant solution.

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

Sidebar

Related Questions

We have lots of WCF services that are only used by our own code;
I'm writing a few WCF services that expose data being retrieved from the Entity
Our WCF services occaisionally spawn a worker thread to handle something that the client
In WCF services and a variety of other .NET apps, I understand that app.config
We are creating some WCF services that will initially be consumed by .NET clients
I have a 2 WCF services that are exposing the same object. Lets say
I'm writing a WCF services that will be exposed to number of customers. Some
I have several WCF services that I have imported into a .Net4 Class Library.
Can we two WCF services where one service contract derives from another and have
I have several WCF services in a test harness that have some similar functionality,

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.