Microsoft Developer Network > Forums Home > Commerce Server Forums > Commerce Server 2007 > how to read userobjectprofile properties like telephone in the login page from the starter site
Ask a questionAsk a question
 

Answerhow to read userobjectprofile properties like telephone in the login page from the starter site

  • Tuesday, October 27, 2009 10:38 AMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    how to read userobjectprofile properties like telephone in the login page from the starter site
    I tried something like this:
    string sTelephone=(string)CommerceContext.Current.USerProfile.Properties["GeneralInfo.tel_number"];

    But this is not working.

    Using starter Site CS2007.
    We are implementing this the login.aspx.cs page
    please be specific regarding using references, etc.

    Thanks
    Diegolo

Answers

  • Wednesday, October 28, 2009 2:33 PMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I got the solution!

    Since we have the email we can follow this article: http://msdn.microsoft.com/en-us/library/aa545403.aspx
    (How to Find the Profile of the Current User)

    try
        {
            // Get the current CommerceContext.
            CommerceContext csContext = CommerceContext.Current;

            // Return a profile after looking it up by e-mail_address.
            Profile profile = csContext.ProfileSystem.GetProfile("GeneralInfo.email_address", emailAddress, "UserObject");
    }

    then we do:

    string sTelephone=profile["GeneralInfo.tel_number"].Value.ToString();

    Thanks  a lot to Gael Duhamel for trying hard on this!!!


    Diegolo
    • Marked As Answer byDiegolo Wednesday, October 28, 2009 2:33 PM
    •  

All Replies

  • Tuesday, October 27, 2009 1:51 PMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    To use a custom propery in the GeneralInfo section:
    String sTelephone = CommerceContext.Current.UserProfile["GeneralInfo.tel_number"].Value

    May be the issue comes from somewhere else. Can you provide more details on the error, like error message, trace,...
    http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com
  • Tuesday, October 27, 2009 2:43 PMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    HI,
    I did this:
    string sTelephone = CommerceContext.Current.UserProfile["GeneralInfo.tel_number"].Value.ToString();

    But got this error:

    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
      Source="App_Web_kltuxtbt"
      StackTrace:
           at User_Login.OnLoad(EventArgs e) in c:\inetpub\wwwroot\User\Login.aspx.cs:line 264
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:

    Thanks!!!
    Diegolo
  • Tuesday, October 27, 2009 5:58 PMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Are you sure that the CommerceContext.Current.UserProfile is not null? Did you try with an existing property?
    http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com
  • Tuesday, October 27, 2009 8:05 PMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks,

    Apparently it is null.

    We are using a custom userid to identify the user.

    How can we call the CommerceContext.Current.UserProfile  for this userid

    Thanks


    Diegolo
  • Wednesday, October 28, 2009 12:06 AMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Which OS are you running on?
    http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com
  • Wednesday, October 28, 2009 1:24 AMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Windows Server 2008.
    Thanks
    Diegolo
  • Wednesday, October 28, 2009 8:59 AMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Try to update the web.config file. I'm quite sure that your HttpModule are blocked by IIS:
    <system.webServer>
        <modules>
          <add name="CommerceApplication" type="Microsoft.CommerceServer.Runtime.CommerceApplicationModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceOrder" type="Microsoft.CommerceServer.Runtime.Orders.CommerceOrderModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceCatalog" type="Microsoft.CommerceServer.Runtime.Catalog.CommerceCatalogModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceProfile" type="Microsoft.CommerceServer.Runtime.Profiles.CommerceProfileModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceExpressionEvaluator" type="Microsoft.CommerceServer.Runtime.Targeting.CommerceExpressionModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceCache" type="Microsoft.CommerceServer.Runtime.Caching.CommerceCacheModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="CommerceContentSelection" type="Microsoft.CommerceServer.Runtime.Targeting.CommerceContentSelectionModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <!-- only if you run the enterprise version -->
          <add name="CommerceDataWarehouseAuthenticationModule" type="Microsoft.CommerceServer.Runtime.CommerceDataWarehouseAuthenticationModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <!-- only if you use the Starter Site -->
          <add name="SiteModule" type="CommerceSite.SiteModule" preCondition="managedHandler" />    </modules>
        <handlers>
          <add name="CommerceContentRedirect" path="redir.axd" verb="*" type="CommerceComponents.ContentRedirectHandler, CommerceComponents" preCondition="integratedMode,runtimeVersionv2.0" />
          <add name="CommerceSiteCacheRefresh" path="SiteCacheRefresh.axd" verb="*" type="Microsoft.CommerceServer.Runtime.SiteCacheRefresh, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " preCondition="integratedMode,runtimeVersionv2.0" />
        </handlers>
        <validation validateIntegratedModeConfiguration="false" />
        <security>
          <requestFiltering allowDoubleEscaping="true">
          </requestFiltering>
        </security>
      </system.webServer>
    

    http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com
  • Wednesday, October 28, 2009 12:15 PMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Thanks,

    I modified the web.config file like this
    <system.webServer>
    		<modules>
    			<!--<remove name="ScriptModule"/>-->
          <add name="MixedModeAuthentication" type="CommerceComponents.MixedAuthenticationModule" preCondition="managedHandler"/>
          <!-- Commented on 91028-->
    			<!--<add name="MixedModeAuthenticationFixUp" type="CommerceComponents.MixedAuthenticationModuleFixUp" preCondition="managedHandler"/>-->
    			<add name="CommerceApplication" type="Microsoft.CommerceServer.Runtime.CommerceApplicationModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceOrder" type="Microsoft.CommerceServer.Runtime.Orders.CommerceOrderModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceCatalog" type="Microsoft.CommerceServer.Runtime.Catalog.CommerceCatalogModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceProfile" type="Microsoft.CommerceServer.Runtime.Profiles.CommerceProfileModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceExpressionEvaluator" type="Microsoft.CommerceServer.Runtime.Targeting.CommerceExpressionModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceCache" type="Microsoft.CommerceServer.Runtime.Caching.CommerceCacheModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
    			<add name="CommerceContentSelection" type="Microsoft.CommerceServer.Runtime.Targeting.CommerceContentSelectionModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
          <!-- only if you run the enterprise version -->
          <!--<add name="CommerceDataWarehouseAuthenticationModule" type="Microsoft.CommerceServer.Runtime.CommerceDataWarehouseAuthenticationModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>-->
          <!-- only if you use the Starter Site -->
          <add name="SiteModule" type="CommerceSite.SiteModule" preCondition="managedHandler"/>
    			<!--<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
        </modules>
    		<handlers accessPolicy="Read, Script">
    			<!--<remove name="WebServiceHandlerFactory-Integrated"/>
    			<remove name="ScriptHandlerFactory"/>
    			<remove name="ScriptHandlerFactoryAppServices"/>
    			<remove name="ScriptResource"/>
          <remove name="PageHandlerFactory-ISAPI-2.0-64"/>
    			<remove name="PageHandlerFactory-ISAPI-2.0"/>
    			<remove name="PageHandlerFactory-Integrated"/>-->
    			<add name="CommerceContentRedirect" path="redir.axd" verb="*" type="CommerceComponents.ContentRedirectHandler, CommerceComponents" preCondition="integratedMode,runtimeVersionv2.0"/>
    			<add name="CommerceSiteCacheRefresh" path="SiteCacheRefresh.axd" verb="*" type="Microsoft.CommerceServer.Runtime.SiteCacheRefresh, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " preCondition="integratedMode,runtimeVersionv2.0"/>
    			<!--<add name="PageHandlerFactory-Integrated" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode"/>
    			<add name="PageHandlerFactory-ISAPI-2.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
    			<add name="PageHandlerFactory-ISAPI-2.0-64" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
    			<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
        </handlers>
    		<security>
    			<requestFiltering allowDoubleEscaping="true">
    			</requestFiltering>
    		</security>
        <!--httpRedirect enabled="false"/-->
    			<validation validateIntegratedModeConfiguration="false"/>
       </system.webServer>
    But still getting UserProfile as null.

    How can we read this property directly from the database.

    Or how can I read profile properties having user's email.

    Thanks!!!




    Diegolo
  • Wednesday, October 28, 2009 2:33 PMDiegolo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I got the solution!

    Since we have the email we can follow this article: http://msdn.microsoft.com/en-us/library/aa545403.aspx
    (How to Find the Profile of the Current User)

    try
        {
            // Get the current CommerceContext.
            CommerceContext csContext = CommerceContext.Current;

            // Return a profile after looking it up by e-mail_address.
            Profile profile = csContext.ProfileSystem.GetProfile("GeneralInfo.email_address", emailAddress, "UserObject");
    }

    then we do:

    string sTelephone=profile["GeneralInfo.tel_number"].Value.ToString();

    Thanks  a lot to Gael Duhamel for trying hard on this!!!


    Diegolo
    • Marked As Answer byDiegolo Wednesday, October 28, 2009 2:33 PM
    •