Code to Retrieve a Profile and Set an MSCSAuth Ticket

This example shows how to retrieve a profile corresponding to a known user ID using the Commerce Server Profiles resource, and set the userID in an MSCSAuth ticket. For more information about using the Profiles resource, see Example Code for Profile Objects.

  1. Create and initialize the ProfileService object. The sBDSConnect parameter is the connection string to the Profile store where the profile definitions are saved.

    Dim oProfileService
    Set oProfileService = Server.CreateObject("Commerce.ProfileService")
    oProfileService.Initialize sBDSConnect, "Profile Definitions"
    
  2. Retrieve the profile associated with the user ID. If the profile does not exist, redirect the user to a login page.

    Dim oProfileObject
    Set oProfileObject = oProfileService.GetProfile(sUserID, "UserObject")
    If (oProfileObject Is Nothing) Then
        Response.Redirect "Login.asp"
    End If
    
  3. Retrieve the password associated with the profile.

    Dim sProfilePassword
    sProfilePassword = oProfileObject.user_security_password
    
  4. If the submitted password matches the profile password, set the authentication ticket using the AuthManager object, oAuthManager, created and initialized in Code to Create and Initialize AuthManager. If the passwords do not match, redirect the user to the login page.

    If sPassword = sProfilePassword Then
        oAuthManager.SetAuthTicket sUserID, True, 45
    Else
        Response.Redirect "Login.asp"
    End If
    
  5. Release the objects.

    Set oProfileService = Nothing
    Set oProfileObject = Nothing
    Set oAuthManager = Nothing
    

Copyright © 2005 Microsoft Corporation.
All rights reserved.