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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:32:01+00:00 2026-05-16T07:32:01+00:00

Currently I have a service that uses a UserNamePasswordValidator to authenticate the client user.

  • 0

Currently I have a service that uses a UserNamePasswordValidator to authenticate the client user. The code for the validation goes as follows:

  public override void Validate(String userName, String password)
  {
      if (userName == null) || (password == null)
          throw new FaultException("Username and/or password not specified.");
      if (userName != "test") && (password != "tset")
          throw new FaultException("Invalid username and/or password.");
  }

As you can see, the code will always throw an exception when something is wrong.

Now for the question – Is there any reason I should check whether ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated is true inside my OperationContract functions? For example,

  public interface IMyService
  {
      [OperationContract]
      void myOpContract();
  }

  public class MyService : IMyService
  {
      public void myOpContract()
      {
          // Do I really need this conditional statement?
          if (ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated)
              // Proceed as expected
          else
              // Fail?
      }
  }

Any help would be greatly appreciated.

  • 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-16T07:32:02+00:00Added an answer on May 16, 2026 at 7:32 am

    From several comments in this article – Silverlight 3: Securing your WCF service with a custom username / password authentication mechanism and from various tests – the if ([...]PrimaryIdentity.IsAuthenticated) section is not required. Throwing a fault inside the UserNamePasswordValidator does the trick of aborting the security negotiation.

    However, one excellent idea on behalf of the author is that leaving the if ([...]PrimaryIdentity.IsAuthenticated) conditional statement in place helps if in the future a new binding (connection type) is added with no security.

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

Sidebar

Related Questions

We have an external service that is currently accessible via the http (port 80,
I have a dotnet windows service that's currently hung, but running. Is there anyway
I have an application that uses a service to create an ArrayList of custom
I have an internal enterprise app that currently consumes 10 different web services. They're
Currently I have to uninstall the old version of my service before I install
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have a fairly robust server-side validation system in place, but I'm looking
I have been running a web service code on my own machine along with
Reporting Services 2000 Standard Edition (currently RTM but hope to have SP2 soon). I
I currently have speakers set up both in my office and in my living

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.