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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:01:59+00:00 2026-05-27T00:01:59+00:00

So I am working on setting up a WCF service, hosted in iis7. The

  • 0

So I am working on setting up a WCF service, hosted in iis7. The service is a REST service.

Up till now our requirements for authentication were that only domain accounts were going to connect to the service. We are using basic authentication and using impersonation for making calls through our business layer to our DB.

This is all working well.

Now we have the need to allow non-domain accounts to use our service. Due to somethings with IIS I implemented this (http://custombasicauth.codeplex.com/) and a custom membership provider that will (depending on the username passed in) either attempt to Auth against Active Directory, or against a asp.net membership provider. This part is working correctly.

The issue now that I have is that impersonation is not working (which is understandable.) Now, this is where I am lost and need help with direction or clearing of all the fog. What I want to do (and I don’t know if this is possible) is this:

IF a user is a domain user THEN impersonate their account.
IF NOT a domain user THEN impersonate the “generic user domain account”.
As a bonus I would like to this to happen “behind the scene” so that each method we have doesn’t need special logic added to handle this.

I have read a bunch of stuff about identities, policy providers, role providers…and now I am thoroughly confused.

Anyone have some insight into 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-27T00:02:01+00:00Added an answer on May 27, 2026 at 12:02 am

    So after a lot of looking online for more information on impersonation works with IIS, I couldn’t find much helpful info. So I began to look more into “hacking” it in.

    I was using this (http://custombasicauth.codeplex.com/) to allow us to have custom basic authentication with WCF.

    how this module flows is LeastPrivilege.CustomBasicAuthentication.CustomBasicAuthenticationModule.OnEnter()
    is called when a connection is established. This in turn calls
    LeastPrivilege.CustomBasicAuthentication.CustomBasicAuthenticationModule.AuthenticateUser() which, eventually calls
    LeastPrivilege.CustomBasicAuthentication.CustomBasicAuthenticationModule.SetPrincipal(string username)

    I changed SetPrincipal to accept a password also
    private static void SetPrincipal(string username, string password)

    In here I do a simple if on the username (checking for a our domain prefix) to determine if the user is a domain account or not. If it is a domain account I use their username/password to create a WindowsIdentity (I used http://www.codeproject.com/KB/dotnet/UserImpersonationInNET.aspx with a little refactoring to get just the WindowsIdentity). If the user wasn’t a domain account I use a known hardcoded domain account for them.
    I then take this WindowsIdentity and create a WindowsPrincipal and I set that to HttpContext.Current.User

    So this works for us. Impersonation is working. As a side effect of this we don’t need to decorate our WCF methods with the [OperationBehavior(Impersonation = ImpersonationOption.Required)] attribute. I don’t know if this is the “Correct” way of doing it, but I think it is pretty close. I think IIS detects that there is a WindowsPrincipal in Current User and automatically impersonates that account.

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

Sidebar

Related Questions

I have been working on setting up a WCF REST service in .NET 4.0.
I have a WCF service hosted that is returning a byte[] of protobuf-net serialized
I have created one WCF service , which is working fine, now i want
I've got a WCF service that is working for basic queries. I started with
I am setting up a WCF web service that hosts a Lucene.Net / AzureDirectory
I'm working on a WCF service that will be communicating over net.tcp to n
I have a WCF REST service that I customized from the VS2010 online template.
I have a WCF service application with most basic settings working properly on my
I am setting scrollTop and scrollLeft for a div that I am working with.
I'm working on an app (Written in C#) that have a setting to run

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.