views:

99

answers:

4

Hello, I'm wondering if there's another solution to my problem, that's considered more the Sharepoint way. FIrstly, my site is an Internet site, not Intranet. The problem is, all I'm trying to do is save values/variables from page to page in Sharepoint. I know the issue with Session Variables, but this seems to be the only way I can see to accomplish this. I know there are webparts that can store this value, but am I wrong in thinking this won't be persisted from page to page?

Basically, I'll be extending the Content Query Web Part to dynamically filter it's results based off of a variable/value. The user chooses their 'area' from a dropdown, and the CQWP in the site will change and query results based off of this value (It will be a provincial structure as it is a Canadian site, so if someone chooses the province 'Ontario', this value is saved in a global variable, and these extended CQWP that are throughout the site, will get this value, and query lists flagged as Ontario).

Is Session variables the only solution?

Thanks everyone!

A: 

Session variables are not the only solution. You can use Browser Cookies as well.

Not necessarily the 'SharePoint Way', but it is an option.

Muhimbi
A: 

The SharePoint way would probably be to use something in the user profile, although of course that's not as appropriate for an anonymous site. Don't worry too much about going outside the SharePoint way of doing things - with an internet site it's pretty much unavoidable.

I'd recommend a cookie rather than a session variable if you only need to store the one value - simple to use from either client or server code, and none of the potential storage issues you get with the session.

Tom Clarkson
A: 

You can always use database to persist this kind of data. Not mentinoning problems with sessions in SharePoint farm scenario.

Tomas Voracek
A: 

You can read or write or remove persist key/values in web or webapplication level, take a look at SPWeb.Properties Property.

string strKey = "YourKey";
string strValue = "YourValue";

if (web.Properties.ContainsKey(strKey))
    // if property exists then update it
    web.Properties[strKey] = strValue;
else
    // if property doesn't exist then add it
    web.Properties.Add(strKey, strValue);

web.Properties.Update();
Hameds

related questions