Profiles / ProfileProviders with WSS 3 (Not MOSS)
Hello,
We're running an install of WSS 3.0 that is configured for Forms Based Authentication. We have a need to store some properties against each user who visits the site and the logical place seemed to be in the user Profile so I added the following to the web.config for the WSS application:
Code Snippet<profile enabled="true" defaultProvider="ProfileSqlProvider">
<providers>
<clear />
<add
name="ProfileSqlProvider"
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="MembershipDB"
applicationName="GuinnessExtranet"
/>
</providers>
<properties>
<add name="HomeUrl" serializeAs="String" type="System.String" />
</properties>
</profile>Where "MembershipDB" is the same connection string used for the Membership/Role provider and "HomeUrl" is a property that specifies the user's home page.
I tested this code in a separate .NET 2.0 Web application using the following code and it worked perfectly. I opened up the table using SQL Server Studio and the value was added correctly.
Code Snippetpublic
partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
HttpContext.Current.Profile["HomeUrl"] = "http://www.google.com"; HttpContext.Current.Profile.Save();Response.Write(
HttpContext.Current.Profile["HomeUrl"]);}
}
My problem is that the code above does not work on a WSS page. The "Profile" property of HttpContext.Current always seems to be null no matter how I try to access it. Several sources on the net say to use the ServerContext / UserProfileManager in the Microsoft.Office.Server namespace but this is not available in WSS3. Could someone tell me what I'm doing wrong here?
Thanks very much in advance.
Olly
Answers
I have solved this problem:
WSS uses in the web.config before adding it's own handlers. You need to add the ProfileModule back in as follows:
Code Snippet<httpModules>
<clear />
<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
<add name="Profile" type="System.Web.Profile.ProfileModule" />
<!-- <add name="Session" type="System.Web.SessionState.SessionStateModule"/> -->
</httpModules>Lo and behold you can access the Profile object again.
Cheers,
All Replies
I have solved this problem:
WSS uses in the web.config before adding it's own handlers. You need to add the ProfileModule back in as follows:
Code Snippet<httpModules>
<clear />
<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
<add name="Profile" type="System.Web.Profile.ProfileModule" />
<!-- <add name="Session" type="System.Web.SessionState.SessionStateModule"/> -->
</httpModules>Lo and behold you can access the Profile object again.
Cheers,
- You have no idea how valuable you posting that was. I've been tearing my hair out for two hours and Googling this topic kept leading me back to the same "that doesn't help!!" article.
thank you, thank you.
Driss. - Likewise, I had burned hours trying to figure out why I couldn't access Profile information. Thanks.
BTW, I wrote an blog article about what it takes to use ASP.NET profiles on a SharePoint FBA site:
http://blog.beckybertram.com/Lists/Posts/Post.aspx?ID=53
Visit my blog at blog.beckybertram.com or follow me on Twitter: @beckybertram - Brilliant find. Thanks for posting!