Code to Build a Login Page
Use the following code to check for authenticated users, to set tickets to identify users, and to add and modify ticket properties. This code sample requires that the CommerceAuthenticationModule object is configured in the web.config file. For more information about the CommerceAuthenticationModule class, see Commerce Modules and CommerceAuthenticationModule Class. In addition, this code sample should be used within a Commerce Server project. For more information about creating a Commerce Server project, see Creating a Commerce Project.
<%@ Page language="c#" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Profiles" %>
<script language="C#" >
private void Page_Load(object sender, System.EventArgs e)
{
ProfileContext pc;
SiteTerm st;
SiteTermElementCollection stc;
SiteTermElement ste, ste2;
ArrayList stNames;
SiteTermElement [] stElementArray;
Profile profile;
try
{
if (CommerceContext.Current != null)
{
pc = CommerceContext.Current.ProfileSystem;
// Retrieve all the siteterms in the catalog.
stNames = pc.SiteTermNames;
if (stNames.Count > 0)
{
// Retrieve all the elements contained in a particular siteterm
// encapsulated within a SiteTerm class.
st = pc.GetSiteTerm((string)stNames[0]);
// Retrieve ths siteterms in a collection and iterate
// through them.
stc = st.Elements;
Response.Write("SiteTerm: " + stNames[0] + " has " + stc.Count + " elements.<br>");
foreach (SiteTermElement steTemp in stc)
{
Response.Write("Name: " + steTemp.Name + " Value: " + steTemp.Value + "<br>");
}
Response.Write("<br><br>");
// Sort days of the week siteterm and display them.
stElementArray = new SiteTermElement[stc.Count];
stc.CopyTo(stElementArray, 0);
Array.Sort(stElementArray);
Response.Write("SiteTerm: " + stNames[0] + " in sorted order.<br>");
foreach (SiteTermElement steTemp in stElementArray)
{
Response.Write("Name: " + steTemp.Name + " Value: " + steTemp.Value + "<br>");
}
Response.Write("<br><br>");
// Reference the siteterm within the collection by name.
ste = stc["Guest User"];
Response.Write("Reference a siteterm element from a collection by name.<br>");
Response.Write("Name: " + ste.Name + " Value: " + ste.Value + "<br>");
Response.Write("<br><br>");
// Compare siteterm elements.
ste2 = stc["Registered User"];
if (ste.Equals(ste2))
Response.Write("The two SiteTermElement objects are equal.<br>");
else
Response.Write("The two SiteTermElement objects are not equal.<br>");
Response.Write("<br><br>");
// Validate a profile property through the siteterm class.
profile = pc.GetProfile("logon_name", "username", "UserObject");
if (profile != null)
{
// if there really is a profile in the profile store
if (st.Validate(profile.Properties[0]))
Response.Write("The profile property is validated.<br>");
else
Response.Write("The profile property is not valid.<br>");
}
else
Response.Write("The profile does not exist.<br>");
Response.Write("<br><br>");
}
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
</script>
<HTML>
<HEAD>
<title ID=L_Login_HTMLTitle>Login</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="https://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
</body>
</HTML>
See Also
SiteTermElementCollection Class (BCL)
Copyright © 2005 Microsoft Corporation.
All rights reserved.