More in this section

Forums / Developing with Sitefinity / Checking if a given UserName is already registered

Checking if a given UserName is already registered

9 posts, 0 answered
  1. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    03 Sep 2009
    Link to this post
    Hi folks!

    Could you please let me know how can i check if a given username is already registered?

    I am developing a webservice callable through ajax that doesnt let the user proceed until he/she defines a non existent Username.

    I have been playing with UserManager.GetUser but from the docs it only works for  logged users.

    Thanks in advance
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    04 Sep 2009
    Link to this post
    Hi Carlos Souto,

    Thank you for using our services.

    The UserManager.GetUser method has several overloads which allow you to get a user by user name, current user, or get a user by his unique id key in the form of a Guid.  I suppose that you have already figured out how to get the desired user name from the text box, so you could just perform the following simple check:
    //if you are using a different membership provider instantiate myManager 
    //with the name of your provider like that: new UserManager("YourProviderName" 
    //correct method overload is UserManager.GetUser(string username) 
    string userNameToLookFor = "admin"
    UserManager myManager = new UserManager(); 
    MembershipUser user = myManager.GetUser(userNameToLookFor); 
    if (user != null
      { 
       //add your logic 
      } 

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    04 Sep 2009
    Link to this post
    Hello Radoslav!

    Maybe i wasnt clear about this situation.

    The project we are working on is SOA and the webservice is in another project in the same solution as the website.

    I have tried all examples i've seen online not just in telerik website and forums.

    For now the webservice is in the website project and it works but the webservice in the other project doesnt. I was thinking if its the case to read the website web.config so the UserManager in the outer webservice can Get and Create Users.

    Another solution would be to use Client Application Services but i'm rushing out of time.

    Best Regards
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Sep 2009
    Link to this post
    Hello Carlos Souto,

    You can use the code below which uses .NET Framework Membership class.

     
            MembershipUser myuser = Membership.Provider.GetUser(userName, false); 
            if(myuser.UserName !=null
            { 
                // todo 
            } 

    or Membership.GetAllUsers() and check through the collection - this is memory consuming way.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    04 Sep 2009
    Link to this post
    Cheers Ivan!

    I had already tried it without sucess.

    The WebService is in another project, not in the Sitefinity WebSite, and like so we cannot get the Context(?). Also the webservice is calling a Bussiness Logic Layer.

    I have already tried to copy the membership config from web.config to app.config of BLL.

    The only way for this to work is to put the webservice in the sitefinity website but this raises a security issue.

    Best Regards
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    09 Sep 2009
    Link to this post
    Hello Carlos,

    What kind of security exception do you get?

    Also, are you trying to check if the user exists in Sitefinity (which uses the standard membership provider), or you are trying to check if the user exist in your external tables (used by the web service)?

    Thank you for your cooperation in advance. 

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    09 Sep 2009
    Link to this post
    Hello Georgi!

    I was just about to post my developments regarding this post.

    I have copied the membership/telerik section of the website to the webservice project web.config and it is working.

    Thank you for all the support.

    Best Regards
  8. mathieu cupryk
    mathieu cupryk avatar
    2 posts
    Registered:
    03 Jul 2009
    08 Oct 2009
    Link to this post
    I am in the same boat can someone post the code for this as a zip.

    Thanks.
  9. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    08 Oct 2009
    Link to this post
    Hello!

    There is no trick in getting this to work.

    In your Services Layer(WebServices/WCF) you just need to insert the Sitefinity web.config sections related to membership/role provider and the Sitefinity connection string.

    Hope this helps you.
Register for webinar
9 posts, 0 answered