I'm working with an ASP MVC application and attempting to create a session variable in one controller and then later access that session variable in a different controller. I've found articles about this for PHP but I'm having trouble finding a solution for ASP MVC.
My code right now makes an ajax call to one controller to update an account number:
$.ajax({
type: "PUT",
url: defender.techWebBaseUrl + "jobsinprogress/storenewmonitoringacctnumber/",
data: { acctNum: $("#newAcctNumber").val() }
});
This executes on the controller:
public void StoreNewMonitoringAcctNumber(string acctNum)
{
Session["MAN"] = acctNum;
}
Which successfully creates the session variable. Later on in my workflow, in a completely separate/different controller I attempt to access this same variable:
.Configure(job, type, "sent", licenseStamp, EmployeeSignatureKey, Session["MAN"].ToString());
But every time that Session variable is NULL. I'm trying to understand how to persist Session variables in MVC because obviously the same rules from ASP.NET Web forms do not apply here. Also, these actions of saving the Session variable then attempting to access the Session variable must exist on different controllers so I absolutely must find a way to persist that variable.
Any advice is appreciated.