tags:

views:

262

answers:

1

As part of a MOSS 2007 solution, I've got a web part that displays a 'term' of the day. The terms are stored in a horribly messy XML file so it all gets parsed nicely and then is supposed to update a property called LastUpdatedOn to the current time.

My problem is that administrator level accounts can see this with no problems whatsoever, but viewers are getting an error stating that they have insufficient privileges to save the properties of the web part.

I'm running the code within an elevated privileges delegate, and have instantiated a new context to get around the fact that the context still thinks the current user is not the system account.

Pastebin of full code can be found here

The problem lines are:

SaveProperties = true;
LastUpdatedOn = DateTime.Now.ToString();

Commenting these out means that my web part works, but it will always display a random term on every page load instead of keeping the same term for 24 hours.

+2  A: 

Why not base your seed on todays date and skip saving a value?

Sample:

Random r = new Random(DateTime.Now.DayOfYear + 365 * DateTime.Now.Year);
r.Next(count);

This will give you a new random value each day.

JMD