Link to home
Start Free TrialLog in
Avatar of smithmrk
smithmrkFlag for United States of America

asked on

VB.net 2013 - Windows Forms ASP Membership Provider - Profiles?

I'm using the ASP.net Membership Provider in my Windows Application, but I can't seem to figure out how to access the Profile Information?

For Example the First Name, Last Name, Department, etc.

Thanks,
Mark
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Did you define the profile properties in the web.config?

<profile>
	<properties>
		<add name="Name" allowAnonymous="true"/>		
		<add name="VisitedOn" type="System.DateTime" allowAnonymous="true"/>			
	</properties>
</profile>

Open in new window


Implementing User Profiles in ASP.NET - A Beginner's Guide
http://www.codeproject.com/Articles/420052/Implementing-User-Profiles-in-ASP-NET-A-Beginners#33
Avatar of smithmrk

ASKER

Windows Application...so there is no web.config, only the app.config.
I want to access the ASP Membership Provider through a Windows Application and get the profile information.

Thanks,
Mark
Mark,

That is outside of what I have ever worked with.  I would think that if you put the configuration in the app.config file, that it might work.
Sorry it has taken me so long to get back to you...

This one here is my best lead:
https://mdrasel.wordpress.com/2011/02/01/asp-net-membership-provider-outside-of-web-application/

However, it only shows me how to create a profile...I already have the profiles created I just need to get the information from the profile.  How can I do that?

ProfileBase profile = ProfileBase.Create(“testuser”, true);
profile.SetPropertyValue(“FriendlyName”, “testuser”);
profile.SetPropertyValue(“TagID”, “123321”);
profile.Save();

Thanks,
Mark
OK, so this is what I have:

Try
            Dim test As ProfileBase = New ProfileBase
            test.Initialize("msmith", True)

            MessageBox.Show(test.GetPropertyValue("FirstName"))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

But I'm getting this error message see attached screen shot.

Mark
error.jpg
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Security.SqlProfileProvider" applicationName="AspNet" connectionStringName="LocalSqlServer"/>
      </providers>
      <properties>
        <add name="FirstName" type="string"/>
        <add name="LastName" type="string"/>
        <add name="JobTitle" type="string"/>
        <add name="Gender" type="string"/>
        <add name="ProfileImageID" type="string"/>
        <add name="Department" type="string"/>
        <add name="PhoneNumber" type="string"/>
        <add name="MobilePhone" type="string"/>
      </properties>
    </profile>
Found my problem!!!
In bold below:

<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Security.SqlProfileProvider" applicationName="AspNet" connectionStringName="LocalSqlServer"/>
      </providers>
      <properties>
        <add name="FirstName" type="string"/>
        <add name="LastName" type="string"/>
        <add name="JobTitle" type="string"/>
        <add name="Gender" type="string"/>
        <add name="ProfileImageID" type="string"/>
        <add name="Department" type="string"/>
        <add name="PhoneNumber" type="string"/>
        <add name="MobilePhone" type="string"/>
      </properties>
    </profile>
Now my problem is this is returning nothing...blank messagebox:

MessageBox.Show(test.GetPropertyValue("FirstName"))
However, this means that you are able to grab the profile so its a good start. Try some other properties.
Nope, nothing!
They are all coming back blank.

???

Mark
Is the table populated in DB?
Yes, because it works fine when I log into my Web Page side of the house...but doesn't seem to pull the values in the Windows Application.

I keep looking, but so far my connection string, and everything else seems to be working.

Mark
OK, I finally figured this out!
It did have to do with my app.config file.

This is what I have now and works:

    <profile enabled="true">
      <properties>
        <add name="FirstName" type="string"/>
        <add name="LastName" type="string"/>
        <add name="JobTitle" type="string"/>
        <add name="Gender" type="string"/>
        <add name="ProfileImageID" type="string"/>
        <add name="Department" type="string"/>
        <add name="PhoneNumber" type="string"/>
        <add name="MobilePhone" type="string"/>
      </properties>
    </profile>

Thanks,
Mark