Вы могли бы записать ли пользователь посетил страницу в сессии. Вы могли бы просто разместить bool в сеансе по пути к странице. Таким образом, он будет доступен для отдельного пользователя, и он будет работать в течение всего сеанса.
Для записи, которые пользователь посетил страницу, которую вы могли бы сделать следующее:
HttpContext.Current.Session[pagePath] = true;
и получить ли пользователь посетил страницу, которую вы могли бы сделать это:
bool hasUserVisitedPage = (bool)HttpContext.Current.Session[pagePath];
Вот как он собрался бы в пределах вашей загрузки страницы:
protected void Page_Load(object sender, EventArgs e)
{
//set the default for whether the user visited the page
bool hasUserVisitedPage = false;
//get the path of the page
string pagePath = HttpContext.Current.Request.Url.LocalPath;
//find out if the user visited the page by looking in the session
try { hasUserVisitedPage = (bool)HttpContext.Current.Session[pagePath]; }
//we don't care if the value wasn't present (and therefore didn't cast)
catch {}
//if the user hasn't visited the page before
if (!hasUserVisitedPage)
{
//record that the page has now been visited
HttpContext.Current.Session[pagePath] = true;
//put the rest of your load logic here...
}
}
Если вы хотите включить эту технику nique на нескольких страницах я бы инкапсулировал эту функциональность в класс-помощник, чтобы вы не повторяли себя.
public static class PageHelper
{
public static bool hasPageBeenViewed()
{
//set the default for whether the user visited the page
bool hasUserVisitedPage = false;
//get the path of the page
string pagePath = HttpContext.Current.Request.Url.LocalPath;
//find out if the user visited the page by looking in the session
try { hasUserVisitedPage = (bool)HttpContext.Current.Session[pagePath]; }
//we don't care if the value wasn't present (and therefore didn't cast)
catch {}
//if the user hasn't visited the page before
if (!hasUserVisitedPage)
{
//record that the page has now been visited
HttpContext.Current.Session[pagePath] = true;
}
return hasUserVisitedPage;
}
}
Тогда было бы значительно упростить логику нагрузки на следующее: (Это даст вам дополнительное преимущество логики, находящейся в центре города, что было бы очень удобно, если вам необходимо изменить его)
protected void Page_Load(object sender, EventArgs e)
{
//if the user hasn't visited the page before
if (!PageHelper.hasPageBeenViewed())
{
//put the rest of your load logic here...
}
}