angularjs and asp.net sessions RRS feed

  • Question

  • 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;
                            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)
                    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)
                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.

    Friday, April 24, 2015 5:55 AM


  • User-1652363262 posted

    these lines in web.config of my service project fixed it

            <add name="Access-Control-Allow-Origin" value="https://localhost:44302" />
            <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
            <add name="Access-Control-Allow-Credentials" value="true" /> 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2015 10:56 AM