Commerce Server General - Setting PageGroup throws error on refresh

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > October 2005 > Setting PageGroup throws error on refresh





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Setting PageGroup throws error on refresh
BeerBoy

2005-09-29, 5:58 pm

I have a page which displays a banner ad using the 'PageGroup'
functionality. All works, except when you hit the browser 'refresh'
button (or when a Postback is performed !). Anyway, the line which sets
the PageGroup fails i.e this line :

csContext.TargetingSystem.TargetingContextProfile["PageGroup"].Value =
"Sports";


Thinking I was doing something wrong I tried the example from the
documentation (attached at bottom of this mail) and it too fails for
the same reason on the second click of the button.

I'm totally stuck on this - any ideas are more than welcome.

Regards

Jim

Cut and paste from :
mk:@MSITStore:D:\Program%20Files\Microso
ft%20Commerce%20Server%202002\Documentat
ion\Commerce_Server.chm::/htm/cs_net_examplestargeting_nakz.htm


<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Profiles" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Caching" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Targeting" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Pipelines" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Diagnostics" %>

<HTML>
<HEAD>
<script language="C#" runat="server">

public void ShowAds_OnClick(Object sender, EventArgs args)
{
CommerceContext csContext = CommerceContext.Current;
//
// Create a targeting profile.
//

csContext.TargetingSystem.TargetingContextProfile["PageGroup"].Value =
"Sports";
//
// Create a user profile
//
Guid guid = Guid.NewGuid();
Profile userProfile =
csContext.ProfileSystem.CreateProfile
(

guid.ToString(),

"UserObject"
);
//
// Get a ContentSelector and set its properties
//
ContentSelector cso =
csContext.TargetingSystem.SelectionContexts["advertising"].GetSelector();

cso.Profiles.Add("targetingContext",
csContext.TargetingSystem.TargetingContextProfile);
cso.Profiles.Add("user", userProfile);
cso.TraceMode = true;
cso.ItemsRequested = 2;
cso.Size = "Half";
//
// Get some content
//
StringCollection content = cso.GetContent();
//
// Bind the results to a repeater
//
if (content.Count > 0)
{
repeaterShowAds.DataSource = content;
repeaterShowAds.DataBind();
}
//
// Dump out Trace Messages
//
if (cso.TraceMessages != null)
{
csContext.DebugContext.Trace("Targeting Sample",
"Trace Messages");
int index = 0;
foreach (StringCollection messages in
cso.TraceMessages)
{
csContext.DebugContext.Trace("Targeting
Sample", "Content item row index=" + index++);
foreach (string message in messages)
{
csContext.DebugContext.Trace("Targeting
Sample", message);
}
}
if (index == 0)
{
csContext.DebugContext.Trace("Targeting Sample",
"It looks like there were no ads on schedule");
}
}
else
{
csContext.DebugContext.Trace("Targeting Sample",
"ContentSelection tracing is unavailable.");
}
csContext.DebugContext.Trace("Targeting Sample",
"Dumping out contents of selectionContext...");
ContentSelectionContext selectionContext =
csContext.TargetingSystem.SelectionContexts["advertising"];
foreach (string key in selectionContext)
{
csContext.DebugContext.Trace("Targeting Sample",
"key=" + key + " value=" + selectionContext[key].ToString());
}
}
</script>
</HEAD>
<body>
<form ID="Targeting" method="post" runat="server">
<h3 id="H31" align="left" runat="server">
Display an advertisement targeting the UserObject and
TargetingContext
profiles.</h3>
<H4 class="dtH4">You should create an ad with a Target
Group associated with the <B>Sports</B>
page group before running this example.&nbsp;</H4>
<P class="dtH4">
<asp:Button id="ButtonShowAds" Text="Show Sports Ads"
runat="server" OnClick="ShowAds_OnClick" /></P>
<P class="dtH4">
<asp:Repeater id="repeaterShowAds" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>Sports Ads</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</TABLE>
</FooterTemplate>
</asp:Repeater></P>
</form>
</body>
</HTML>

BeerBoy

2005-10-24, 10:38 am

Fixed it !!!!

It seems that the Targeting Conrtext profile was set up such that the
'Page Group' property was a key !!!

I simply created a new key property, took the key dependancy off od
'Page Group' and everything worked.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com