|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace Utils
{
public class SessionManager
{
private const string CD = "UserId";
private const string USER_NAME = "UserName";
private const string ACCESS_LEVEL = "AccessLevel";
private const string SCHEMA = "Schema";
private const string SITE_CODE = "SiteCode";
private const string PAYOR_NANE = "PayorName";
private const string CACHING = "Caching";
private const string CLIENT_KEY = "ClientKey";
private const string USER_GRP_CD = "CorporateCode";
//============================
private const string KEY_PRIMARY = "KeyPrimary";
private const string PAGE_INDEX = "PageIndex";
//====================
public static string PageIndex
{
get
{
if (HttpContext.Current.Session[PAGE_INDEX] == null)
{
return string.Empty;
}
else
{
return HttpContext.Current.Session[PAGE_INDEX].ToString();
}
}
set
{
HttpContext.Current.Session[PAGE_INDEX] = value;
}
}
public static string KeyPrimary
{
get
{
if (HttpContext.Current.Session[KEY_PRIMARY] == null)
{
return string.Empty;
}
else
{
return HttpContext.Current.Session[KEY_PRIMARY].ToString();
}
}
set
{
HttpContext.Current.Session[KEY_PRIMARY] = value;
}
}
public static string UserId
{
get
{
if (HttpContext.Current.Session[CD] == null)
{
//Make sure that the user will be redirected to Login Page
//when the sesion expires
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[CD].ToString();
}
}
set
{
HttpContext.Current.Session[CD] = value;
}
}
public static string CorporateCode
{
get
{
if (HttpContext.Current.Session[USER_GRP_CD] == null)
{
//Make sure that the user will be redirected to Login Page
//when the sesion expires
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[USER_GRP_CD].ToString();
}
}
set
{
HttpContext.Current.Session[USER_GRP_CD] = value;
}
}
public static string UserName
{
get
{
if (HttpContext.Current.Session[USER_NAME] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[USER_NAME].ToString();
}
}
set
{
HttpContext.Current.Session[USER_NAME] = value;
}
}
public static string AccessLevel
{
get
{
if (HttpContext.Current.Session[ACCESS_LEVEL] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[ACCESS_LEVEL].ToString();
}
}
set
{
HttpContext.Current.Session[ACCESS_LEVEL] = value;
}
}
public static string Schema
{
get
{
if (HttpContext.Current.Session[SCHEMA] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[SCHEMA].ToString();
}
}
set
{
HttpContext.Current.Session[SCHEMA] = value;
}
}
public static string SiteCode
{
get
{
if (HttpContext.Current.Session[SITE_CODE] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[SITE_CODE].ToString();
}
}
set
{
HttpContext.Current.Session[SITE_CODE] = value;
}
}
public static string PayorName
{
get
{
if (HttpContext.Current.Session[PAYOR_NANE] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[PAYOR_NANE].ToString();
}
}
set
{
HttpContext.Current.Session[PAYOR_NANE] = value;
}
}
public static bool Caching
{
get
{
if (HttpContext.Current.Session[CACHING] == null)
{
//Logout();
return false;
}
else
{
return (bool)HttpContext.Current.Session[CACHING];
}
}
set
{
HttpContext.Current.Session[CACHING] = value;
}
}
public static string XPClient
{
get
{
if (HttpContext.Current.Session[CLIENT_KEY] == null)
{
//Logout();
return string.Empty;
}
else
{
return HttpContext.Current.Session[CLIENT_KEY].ToString();
}
}
set
{
HttpContext.Current.Session[CLIENT_KEY] = value;
}
}
//private static void Logout()
//{
// ErrorHandler errorHandler = new ErrorHandler();
// errorHandler.CatchError(ErrorType.SESSION, "");
//}
public static string SetSession(string sessionName, string sessionValue)
{
HttpContext.Current.Session[sessionName] = sessionValue;
return HttpContext.Current.Session[sessionName].ToString();
}
public static string GetSession(string sessionName)
{
if (HttpContext.Current.Session[sessionName] != null)
{
return HttpContext.Current.Session[sessionName].ToString();
}
else
{
//Logout();
return string.Empty;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
MCTS - Microsoft Certified Technology Specialist.
An Accountant.
Had been developed Payroll Accounting System Application
Live in: Quezon City, Metro Manila Philippines
Could reached at email address: ag_mojedo@live.com