I'm looking at the code user registration in the public templates and it uses the Create user-wizard from the asp.net framework. What I can't figure out is where to find the insert-command? Where is it located?
The wizard calls the Membership-providers implementation of CreateUser().
Can I find this and alter it? I'd like to add a variable to the registration.
You can hook the CreatingUser event of the CreatUserWizard control.
Use the ASP.NET membership profile for this: http://www.4guysfromrolla.com/articles/101106-1.aspx
I've read the article and done some further research but I don't understand how it works. I've added a line to the web.config that I want to use, it's <add name="Location" type="System.Int" />. I found another article telling me how to go about but I still can't seem to get it to work. I get stuck on not knowing where to find the ProfileCommon-class.
Ah, yeah you need to create the ProfileCommon class, you can use this tool to generate it: http://code.msdn.microsoft.com/WebProfileBuilder. The article uses the WebSite project which gets compiled during runtime, EPiServer uses the web application project which you need to compile into a dll file before (hence needing to add the ProfileCommon class manually.
Hope this helps.
I installed it and added the import-line to my project like he said in his blog post but still no Profile or ProfileCommon. Is there anything else that needs to be done?
What happens after you build the project?
Nothing in particular. It compiles.
What I've done so far is that I ran the installer for Web Profile Builder, added the <Import Project="$(MSBuildExtensionsPath)\WebProfileBuilder\WebProfileBuilder.targets" /> to my .csproj-file. The first time I ran the solution I got the question if I wanted to load the project for browsing or normally so I choose normally. When compiling nothing out of the ordinary happens and no sight of ProfileCommon.
Have I missed a step?
I'm still stuck on this step. Has someone got a tip on how to get past it?
I suggest you skip the ProfileCommon altogether and simply access the profiledata through the ProfileBase-class instead:
int location = (int)HttpContext.Current.Profile["Location"];
HttpContext.Current.Profile["Location"] = location;
On what event do I set Location? I've tried OnCreatingUser and OnCreatedUser but I end up getting "This property can not be set for anonymous users".
Yeah, in your web.config under the <profile><properties> section you should have the following:<add name="Location" type="System.Int32" />
I found it, sorry. I need to think before asking. :)
I'd hook up to the OnCreatedUser, and instead of using HttpContext.Current.Profile (which requires the user to be currently logged in),use:
ProfileBase.Create(createUserWizard1.UserName)["Location"] = 10;
(assuming the CreateUserWizard control is named "createUserWizard1" )
I tried this and when I try to get the Location on another page I always end up getting 0. Any idea on what could be the problem?
You need to call Profile.Save() for changes to be committed to the profileprovider.
Also, for the profile to be available on the other page, the user must be logged in.
Where do I locate Profile.Save? Is it HttpContext.Current.Profile.Save() ?
If the user is not logged in, you could somehting like this:
ProfileBase userProfile = ProfileBase.Create("username");userProfile["Location"] = 10;userProfile.Save();
Great, that did the trick!
Thanks a million!