Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ID 27 posts 128 karma points
    Mar 07, 2013 @ 21:38
    ID
    0

    How to get a membertype field property value of a Member

    Hello,

    I've posted in an other thread but that is for 4.11 (and i'm using 6.0.2 with Mvc enabled) and I could not find a way to delete the reply.

    I have implemented a Surface controller to login a member and redirect it to a specific page. I want to decide which page to redirect to upon the property value of a member (using membertype/profile property with content picker datatype).

    I did not succeeded though using the ASP.NET Membership Profile Provider. The only thing I can find is to Create and Save the property, but I only want to GET the property value.

     

    There's no such method as MembershipUser.GetProperty("somepropertyname")... 

     

    The next code I used successfully, but this is with the deprocated method "Member.GetMemberByName". How would anyone rewrite it using the ASP.NET profile providers? Or else maybe some docs, or a ubraco.tv thingy covering this?

     

            [HttpPost]
            [ActionName("MemberLogin")]
            public ActionResult HandleMemberLogin(MemberLogin model)
            {
                if (!ModelState.IsValid)
                {
                    return CurrentUmbracoPage();
                }
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                }
                else
                {
                    ModelState.AddModelError("Username", "Gebruikersnaam of wachtwoord is onjuist.");
                    return CurrentUmbracoPage();
                }
                Member member = Member.GetMemberByName(model.Username, true).FirstOrDefault();
                if (member != null)
                {
                    var propertyValue = member.getProperty("home").Value;
                    int pageId = Convert.ToInt32(propertyValue);
                    return RedirectToUmbracoPage(pageId);
                }
                return Redirect("/");
            }
  • ID 27 posts 128 karma points
    Mar 07, 2013 @ 23:17
    ID
    100

    Ok already solved it!

    I was missing the custom default provider for the profile in the web.conf and needed to set the property there, another way is to set this property is to create a class which inherits from Providerbase and add a property there:

    <system.web>

    ...

        <!-- Profile provider-->

        <profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" inherits="UmbracoFramework.Models.MemberProfile, UmbracoFramework">

          <providers>

            <clear />

            <add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />

          </providers>

          <properties>

            <clear />

            <add name="home" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />

          </properties>

        </profile>

    </system.web>

    Now it works like this:

            [HttpPost]

            [ActionName("MemberLogin")]

            public ActionResult HandleMemberLogin(MemberLogin model)

            {

                if (!ModelState.IsValid)

                {

                    return CurrentUmbracoPage();

                }

     

                if (Membership.ValidateUser(model.Username, model.Password))

                {

                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                }

                else

                {

                    ModelState.AddModelError("Username", "Gebruikersnaam of wachtwoord is onjuist.");

                    return CurrentUmbracoPage();

                }

     

                var memberProfile = ProfileBase.Create(model.Username);

                var propertyValue = memberProfile.GetPropertyValue("home");

     

                if (propertyValue != null)

                {

                    int pageId = Convert.ToInt32(propertyValue);

                    return RedirectToUmbracoPage(pageId);

                }

     

                return Redirect("/");

            }

  • Charles Afford 1163 posts 1709 karma points
    Mar 09, 2013 @ 21:25
    Charles Afford
    0

    Instead of:

    GetPropertyValue("home")

    you can just use: 

    profile["home"].ToString()

    you probably want to declare that "home" as a const string rather that putting it straight in :).

    Charlie. :)

Please Sign in or register to post replies

Write your reply to:

Draft