Skip to main content

Session Management

Introduction

After login, Damsy ERP stores nearly all request context in ASP.NET session state. Session keys carry company scope, user identity, role, module access flags, payroll defaults, mail settings, and e-invoice API configuration. Most controller actions begin by reading Session["CompID"]; many also read Session["dtVerifyUser"] for module booleans.

Purpose

This page is the authoritative reference for which session keys exist, what they mean, when they are set, and how they relate to authorization — without relying on a non-existent ModuleAccess key.

When to Use

Consult this page when you:

  • Add a new controller action that needs company or user context
  • Debug "redirect to login" loops
  • Wire e-invoice or SMTP features that read session
  • Determine whether a user should see a module tile or menu

How It Works

Session lifecycle overview

Keys set at login

KeyTypeDescription
CompIDint (as string)Primary gate. Selected company ID. Required on almost every action.
CompNamestringDisplay name of selected company
UserIDintUserAccountsID from database
UserNamestringDisplay name
RolestringRole name (e.g. Administrator)
RoleIdintRole ID — session key is RoleId, not RoleID
BranchCodeintUser's assigned branch
dtVerifyUserBO.UserFull user object including module boolean flags
StartMonthintDefault payroll month for company
StartYearintDefault payroll year for company
Versiondouble/stringApplication software version

Module flags on dtVerifyUser

Module access is stored as boolean properties on the BO.User object in Session["dtVerifyUser"]. There is no Session["ModuleAccess"] key.

User propertyDashboard ViewData keyModule
PayrollPayrollPayroll
WebenrollWebenrollRegistration
BillingBillingBills
ZSTOCKStockModuleAccessStock
ZSalesZSalesSales
EssEssESS
ControlPanelControlPanelAdminisration
AttPunchAttPunchAttendancePunching
OperationOperationOperation
ManagementDashboardManagementDashboardManagmentDashBoard
ContractedRatesContractedRatesContractedRates
VerificationAndApprovalVerificationAndApprovalVerificationAndApproval

The dashboard copies these booleans to ViewData for tile visibility. Area controllers typically re-read dtVerifyUser or rely on menu permission SPs for fine-grained access.

E-invoice and ZAPI keys

Set from GetLoginUser result columns:

Session keyUser propertyPurpose
CDKEYCDKEYE-invoice license / CD key
EFUSERNAMEEFUSERNAMEE-invoice username
EFPASSWORDEFPASSWORDE-invoice password
ZAPIPATHZAPIPATHZAPI server base path (ServerLocation in DB)
GenerateIRNUriGenerateIRNUriIRN generation endpoint
CancelIrnUriCancelIrnUriIRN cancellation endpoint
PrintIRNUriPrintIRNUriIRN print endpoint
PrintEWayBillDetailedPrintEWayBillDetailedDetailed E-Way bill print URL
PrintEWayBillSummaryPrintEWayBillSummarySummary E-Way bill print URL
EWayBillDeliveryChallanEWayBillDeliveryChallanDelivery challan E-Way URL

Bills module IRN integration reads these session values when calling external GST APIs.

SMTP keys

Loaded via Login_DAL.MailConfigure[dbo].[GetEmailConfigration]:

KeyDescription
SMTP_HOSTMail server hostname
SMTP_PORTPort (typically 587 or 25)
SMTP_USERSMTP username
SMTP_PSWDSMTP password

Used when the application sends mail on behalf of the logged-in company context.

Keys set later (situational)

KeyWhen setPurpose
ModuleOpening shared screens (e.g. EmployeeM)Identifies which module owns the shared form
EntryflagAdmin re-authenticationSensitive admin action confirmation via AdminLoginCheckMenu

Logout behavior

LoginController.LogOut:

  1. FormsAuthentication.SignOut()
  2. Session.Clear()
  3. Session.Abandon()
  4. Expire ASP.NET_SessionId cookie
  5. Redirect to Login/Index

Developer Notes

Standard gate pattern

if (string.IsNullOrEmpty(Convert.ToString(Session["CompID"])))
return RedirectToAction("UserLogin", "Login", new { Area = "" });

Reading module access

var user = Session["dtVerifyUser"] as User;
if (user == null || !user.Billing)
return Redirect("~/Dashboard/Index");

Passing context to DAL

var bo = new Some_BO();
bo.CompID = Convert.ToInt32(Session["CompID"]);
bo.UserID = Convert.ToInt32(Session["UserID"]);
bo.BranchCode = Convert.ToInt32(Session["BranchCode"]);

Fine-grained permissions

Menu-level CRUD permissions use GetDataUserPermissions with UserAccountsID, ModuleID, and MenuID — separate from module bool flags. On a minimal blank database seed, menus may be empty even when module flags are true.

Why no ModuleAccess key

Historical designs sometimes used a single comma-separated module list. Damsy ERP uses dtVerifyUser booleans plus per-menu SP permissions instead. Do not introduce Session["ModuleAccess"] without a coordinated migration.

Examples

Dashboard ViewData mapping (DashboardController)

ViewData["Payroll"] = dtVerifyUser.Payroll;
ViewData["Webenroll"] = dtVerifyUser.Webenroll;
ViewData["Billing"] = dtVerifyUser.Billing;
ViewData["StockModuleAccess"] = dtVerifyUser.ZSTOCK;
// ... remaining flags

Bills IRN call using session

var generateUri = Convert.ToString(Session["GenerateIRNUri"]);
var cdKey = Convert.ToString(Session["CDKEY"]);
// HTTP client call to GST provider

Important Notes

RoleId casing

Use Session["RoleId"] exactly. RoleID will return null and break permission or audit logic.

Session size

dtVerifyUser stores the full user object. Avoid adding large binary data to session (employee images are not stored in session by default).

CompID is a string in session

Always use Convert.ToString(Session["CompID"]) for empty checks; use Convert.ToInt32 when passing to DAL/SP.

Common Mistakes

MistakeResult
Checking ModuleAccess session keyAlways null — key does not exist
Using RoleID instead of RoleIdWrong or zero role in updates
Omitting Session.Clear() on loginStale keys from previous user on shared PC
Assuming module flag = menu permissionUser sees tile but gets empty sidebar
Hardcoding company IDMulti-company deployment breaks

Next Steps

  1. Read Session Lifecycle for login-to-logout flow diagram.
  2. Read Module Routing for how flags connect to Area URLs.