User-1652363262 posted
i made a little website with a login and translations, for the translations i need to check the session for what language it should get.
[WebMethod(EnableSession = true)]
public DTOLogin logOn(string username, string password, string returnUrl, string culture)
{
Session["CurrentUI"] = culture;
string EmployerPrefix = ConfigurationManager.AppSettings["EmployerPrefix"].ToString() + "#";
string IPStart = ConfigurationManager.AppSettings["IMIPADS"].ToString();
string IPEnd = ConfigurationManager.AppSettings["IMIPADE"].ToString();
General g = new General();
string Clientipadres = g.GetVisitorIPAddress(false);
string Ldapserver = "";
var result = new DTOLogin();
...........
Session["MainConnection"] = ps.MainConnection;
Session["TG"] = usrctrl;
Session["login"] = 1;
Session["TGSKIP"] = "0";
FormsAuthentication.SetAuthCookie(EmployerPrefix + username, false);
result.LoggedOn = true;
result.SessionId = HttpContext.Current.Session.SessionID;
if (!String.IsNullOrEmpty(returnUrl))
{
result.RedirectUrl = returnUrl;
}
else
{
result.RedirectUrl = "Dashboard";
}
return result;
on my login i send back this dtologin which includes sessionid.
in my rootscope i have my login function (which is working)
$scope.login = function () {
authFactory.login($scope.loginData.userName, $scope.loginData.password, '', 'nl-BE')
.success(function (data) {
var loginModel = data.d;
$scope.IMSec = loginModel.IMSec;
if (loginModel.LoggedOn) {
document.cookie = 'ASP.NET_SessionId=' + loginModel.SessionId + ';Path=/;';
//$cookieStore.put('ASP.NET_SessionId', loginModel.SessionId)
$location.path('/dashboard');
}
else {
$scope.message = "No access"
}
})
};
i checked in chrome developer mode the cookie ASP.NET_SessionId is being created with the right sessionid.
but now once i come into the dashboard the translations will be loaded (as this is the first place my imtranslate directive will be used)
[WebMethod(EnableSession = true)]
public List<DictionaryEntry> getTranslations()
{
General g = new General();
var ps = g.NewPageSorter(); // ps retrieves session variables used in the login
var resPath = HttpContext.Current.Request.PhysicalApplicationPath + "App_GlobalResources\\inMedio.resx";
var t = new System.Resources.ResXResourceReader(resPath);
var myList = new List<DictionaryEntry>();
foreach (DictionaryEntry item in t)
{
myList.Add(item);
}
return myList;
}
it's not a full method yet but it should work but once i try to get my old session vars it seems they're empty and my session wasn't saved.
when i check httpcontext.current.session i see there is a new session instead of using the old one.
it seems to me the session cookie is just being ignored.