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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:54:57+00:00 2026-05-24T03:54:57+00:00

The requirements: WCF 4.0 IIS host Basic authentication with custom source RESTful There are

  • 0

The requirements:

WCF 4.0
IIS host
Basic authentication with custom source
RESTful

There are plenty of examples and ways how to implement the basic authentication, from using UserNamePasswordValidator, trough ServiceAuthorizationManager and IDispatchMessageInspector, etc.

The problem I’m facing is, that the validation actually will fetch much more information from the authentication backend, than yes/no answer. And I want to pass this information somehow to the invoked service methods (i.e. it’ll be full blown User object, with many properties to control the service behavior). I want to avoid a second call to the user store to retrieve the data based on the username, which I can access from the security context.

So far, the closest thing I found is this solution, which uses the WCF REST Starter Kit‘s RequestInterceptor, in which I can inject a subclass of ServiceSecurityContext to carry on my data, and cast ServiceSecurityContext.Current back in the service method.

The problem with the above is, that it’s written for WCF 3.5, and that I would like to avoid using the Starter Kit.

The question: any idea what would be the most appropriate place to hook into in the chain, so I can pass a data from the validation logic to the service. Or to put it another way, where I would be able to replace the security context with my custom one to carry on the load? Or any other carrier mechanism?

What I’m after is that behavior:

Client (could be a browser) tries to use the service: GET https://myservcer/service/data
The server responds with “Basic Authentication Needed”
The client supplies Basic Authentication Header and sends the request again
The server, based on the user/pass in the header, pulls out a User object out of database.
If the user is not found, request authentication again
If the user is found, the User object is somehow passed the service method
All this should happen without making second roundtrip to the database

So far, what I understand is, that UserNamePasswordValidator will not do – there’s no way to pass the User object if I retrieve it there.

I can create a custom IAuthorizationPolicy or SecurityToken (which one), and put the User object in. But … where this should happen. Can I go with UserNameSecurityTokenAuthenticator for this? Is it going to return the right HTTP error code to ask for credentials? How/where I modify the web.config to use my custom stuff? So far I see how set to use a custom UserNamePasswordAuthenticator only.

EDIT: pls check my own answer for my approach. Nevertheless the question was good, and the answers I got were valuable.

  • 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-24T03:54:58+00:00Added an answer on May 24, 2026 at 3:54 am

    We implemented our own authentication HTTP module. The module hooks into the “on request authenticate” event of the HttpApplication and runs the authentication against the backend. The backend is free to return anything it wants (and in our case it returns more than yes/no. The object that gets returned implements the System.Security.Principal.IIdentity interface. Once the authentication succeeds we attach the identity (object returned by auth) to the principal that gets carried in the HttpContext.User.

    Down the pipeline you can access the current context’s User at any point and get all of your identity’s info.

    The only significant drawback of this approach is that it requires ASP.net compatibility, but if you are already running your Rest services like that then it shouldn’t be a problem.

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

Sidebar

Related Questions

I’m trying to implement a dictionary for use with WCF. My requirements are: actual
We have a system where we host a couple of WCF applications in IIS.
Is there a clean way to expose a WCF REST service that requires basic
Is it possible to host a WCF Service in Apache? What are the requirements
Given the extremely high requirements for unpredictability to prevent casinos from going bankrupt, what
Basically my requirement is: WCF Service Application Hosted on IIS 7.0 with Partial Trust
I have a WCF Service with the following requirements: a) The client requests a
My requirement is to call WCF web service from ASP.NET code behind and pass
I am trying to create a WCF Streaming Service. I have two requirements that
I know of the ServiceHost class, that lets me write a custom host for

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.