angularjs - Cookies are undefined for different domains -


in angularjs service

this.getlocalization = function () {         var deferred = $q.defer();         var cultureabbrev = null;         var currentlanguagefromcookie = $cookies.get("currentlanguagecode");         console.log(currentlanguagefromcookie);          if(currentlanguagefromcookie !== undefined){             cultureabbrev = currentlanguagefromcookie;             deferred.resolve(cultureabbrev);         }         else{             this.getuserlanguage()                 .then(function(data) {                     deferred.resolve(data);                 }).catch(function(){                     deferred.resolve("en");                 });                  };          return deferred.promise;     }  this.getuserlanguage = function (){         return $http.get(__env.apipath(subdomain, '/api/language/getuserlanguage'), {withcredentials: true}).then(function (response) {             return response.data;         });     } 

in web api controller

[enablecors(origins: "http://nexus.bt-client.no", headers: "*", methods: "*", supportscredentials = true)] public class languagecontroller : apicontroller {     public string getuserlanguage()     {         var userlanguage = this.settingsservice.getall().firstordefault().language;         setthreadculture(userlanguage);         saveculturetocookie();         return userlanguage;     }      private void saveculturetocookie()     {         httpcookie cookie = new httpcookie("currentuiculture", thread.currentthread.currentuiculture.name);         httpcookie languagecookie = new httpcookie("currentlanguagecode", thread.currentthread.currentuiculture.parent.name);         cookie.expires = datetime.now.addyears(1);         languagecookie.expires = datetime.now.addyears(1);         try         {             system.web.httpcontext.current.response.setcookie(cookie);             system.web.httpcontext.current.response.setcookie(languagecookie);         }         catch (httpexception ex)         {             logger.warn("could not save cookie culture information.", ex);         }     }  } 

in angularjs run method calling getlocalization().

but every page refresh getlocalization() method's else part triggered since currentlanguagecode cookie undefined always. can see after page refresh, in network tab, request cookies , response cookies set correctly. if refresh page again can see previous request's response cookies set request cookies supposed correct. cookie seems not accessible client hence $cookies.get("currentlanguagecode") undefined , else part triggered. happens in server. in localhost works fine.

i have set withcredentials: true , suppose have configured cors correctly(but not sure).

the domain client http://nexus.bt-client.no , server http://nexus.ktvproduct.no.

if needed, local host, front end , end it's http://test.localhost:8090 , http://test.localhost:8080. works fine. issue hosted sites.

all appreciated. thanks!


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -