views:

240

answers:

3

I'm trying to use ASP.net profiles I've followed some instructions which means I have

  1. set up a the ASPNETDB (using SQLExpress 2005)
  2. configured the profile provider (in the web.config)
  3. defined some properties
  4. enabled authentication

But I can't seem to use code like (ie Intellisense doesn't like it)

Profile.UserCustomContent = "Hi Mom";

It's obvious I've missed something major, but I cannot see, please help me...

Here are some snips from my web.config

<connectionStrings>
<add name="SqlServices"
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalogue=aspnetdb" />
</connectionStrings>

<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>

<profile enabled="true" defaultProvider="SqlServices">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider"
connectionStringName="SqlServices" applicationName="MyInternalApplication" />
</providers>


<properties>
<add name="UserSearchFilterOptions" type="String" />
<add name="UserCustomContent" type="String"/>
</properties>
</profile>
</system.web>
+3  A: 

When you add the profile you've called it SqlProvider instead of SqlServices. (the default profile provider name you used above)

typemismatch
lol, still stuck, but this definitely progress :D
DrG
+1  A: 

This is how I do it.. perhaps there's a different way for your situation.

VB - New User.. (True being the value for IsAuthenticated)

Dim profile As ProfileCommon = ProfileCommon.Create(myUser.UserName, True)
profile.UserCustomContent = "customcontent"

VB - Existing User...

Dim profile As ProfileCommon
profile = Profile.GetProfile(myUser.UserName)
profile.UserCustomContent = "customcontent"

C# - New User

ProfileCommon profile = (ProfileCommon) ProfileCommon.Create(myUser.UserName, true);
profile.UserCustomContent = "customcontent";
profile.Save();

C# - Existing User

ProfileCommon profile;
profile = Profile.GetProfile(myUser.UserName);
profile.UserCustomContent = "customcontent";
profile.Save();
madcolor
+1  A: 

If you are using the Web Application Project, you will need to implement profiles yourself. Profiles only work out-of-the-box with the Web Site option. The Web Application Project does not have the Profile object automatically added to each page as with the Web Site project, so we cannot get strongly-typed programmatic access to the profile properties defined in our web.config file.

So, if you are using a Web Application Project, this should help:

http://code.msdn.microsoft.com/WebProfileBuilder

However, if you are using the Web Site Project, then this article from Scott Guthrie should lead you in the right direction:

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

More details on one of my own blog posts on this:

http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx

:-)

IrishChieftain