((UserPart)_membership.CreateUser(...)).As<mypart> returns null

Topics: Troubleshooting
Mar 26, 2012 at 10:45 AM
Edited Mar 26, 2012 at 11:56 AM

I need to create a new user and directly afterwards access my custom part that is attached to the user.

Problem is that the .As<> returns a null value.

Anyone got a clue what I'm doing wrong :s

edit: Still going & failing - any aid would be greatly appreciated!

edit2: Ok I think I got it, I was missing the following @ my content handler:

Filters.Add(new ActivatingFilter<MyPart>("User"));

Developer
Mar 26, 2012 at 6:05 PM
Edited Mar 26, 2012 at 6:08 PM

Do not use direct casting to UserPart. Instead, try:

_membership.CreateUser(...).As<mypart>

The CreateUser methods returns a object if type IUser, which is an IContent, so you can use .As<MyPart> method on it. That IUser object do not derive in any way from UserPart, so direct casting is incorrect here.

In general, always use .As<> method to move between different parts on a content item. Casting is of no use here.

Mar 26, 2012 at 6:37 PM
pszmyd wrote:

Do not use direct casting to UserPart. Instead, try:

_membership.CreateUser(...).As<mypart>

The CreateUser methods returns a object if type IUser, which is an IContent, so you can use .As<MyPart> method on it. That IUser object do not derive in any way from UserPart, so direct casting is incorrect here.

In general, always use .As<> method to move between different parts on a content item. Casting is of no use here.

I wasn't aware of that, thanks!