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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:22:19+00:00 2026-06-18T06:22:19+00:00

I have create a method that should return an attributes soredin Active Directory for

  • 0

I have create a method that should return an attributes soredin Active Directory for a logged in User using Membership.

I receive this error The parameter 'username' must not be empty. any idea how to solve it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.DirectoryServices.AccountManagement;
using System.Threading;

   public static string SetGivenNameUser()
    {
        string givenName = string.Empty;
        MembershipUser user = Membership.GetUser();
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
        UserPrincipal userP = UserPrincipal.FindByIdentity(ctx, user.UserName);
        if (userP != null)
            givenName = userP.GivenName;
        return givenName;
    }

STACK

ArgumentException: The parameter 'username' must not be empty.
Parameter name: username]
   System.Web.Util.SecUtility.CheckParameter(String& param, Boolean checkForNull, Boolean checkIfEmpty, Boolean checkForCommas, Int32 maxSize, String paramName) +2386569
   System.Web.Security.ActiveDirectoryMembershipProvider.CheckUserName(String& username, Int32 maxSize, String paramName) +30
   System.Web.Security.ActiveDirectoryMembershipProvider.GetUser(String username, Boolean userIsOnline) +86
   System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +63
   System.Web.Security.Membership.GetUser() +19
  • 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-06-18T06:22:21+00:00Added an answer on June 18, 2026 at 6:22 am

    Except when you just set authorization, in which case the httpcontext object needs to be reset, the most reliable way to get username is

    HttpContext.Current.User.Identity.Name
    

    so, refactoring your code would look like this:

    UserPrincipal userP = UserPrincipal.FindByIdentity(ctx, HttpContext.Current.User.Identity.Name);
    

    Reason for this is, some objects have their own local ‘hooks’ into membership. And sometimes those hooks haven’t been filled my the httpcontext object yet.

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

Sidebar

Related Questions

I have the following method that should create a 20 character ID (sometimes with
I have created a method that should ideally take a single Account object and
I have a winforms application and I am trying to create a method that
Hi I want to create a WCF service that have login method, which is
I want to create a Javascript class/object that allow me to have various method:
I have created a custom method that will return unique items, together with the
I have a wxFilenName mydir that should point to a writeable directory. Ultimately, mydir
I have a django charField that is checked via the is_valid() method. The user
I have a method that creates a local textfield and pops up the keyboard
I have created a new method in one of the project's controllers that it

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.