Reputation: 507
In my ASP.Net app i use viewstate to store data of a grid, i use common class for creating viewstate object, like shown below.
public static PageViewState CurrentViewState
{
get
{
if (_app == null)
{
Initialize();
}
return _app;
}
}
/// <summary>
/// Creates new object for singleton class
/// </summary>
private static void Initialize()
{
PageViewState _viewstate = new PageViewState();
_app = _viewstate;
}
/// <summary>
/// Returns viewstate for specified page name
/// </summary>
/// <param name="_page">string : Name of the page</param>
/// <returns></returns>
public object this[string _page]
{
get
{
if (ViewState[_page] != null)
return ViewState[_page];
else
return null;
}
set
{
ViewState[_page] = value;
}
}
I'm using a static property, is it safe when multiple users access this in aspx.cs.
Datatable _dtable = (Datatable)PageViewState.CurrentViewState["MyPage"];
ViewState stores data in client side in the form of hiddenfields so it should be unique for each user, am i right about this.
Upvotes: 2
Views: 1806
Reputation: 22619
ViewState is encrypted string representing the control state and it is at the page level.
This is rendered for each page with the hidden input field.
<input type="hidden" id="__ViewState" value="uxudhk.." />
Each page requested by a different user will have a different hidden field in a page. So this is safe always. In case if your ViewState is modified or altered you will get an Server side error like InValid ViewState.
Upvotes: 1
Reputation: 8960
Yes it is as it stores data on the client side i.e. the page user is viewing on his machine.
So you will be seeing the different version of same page(in the sense of viewstate data) and I will be seeing the different version.
Upvotes: 1