Resolve string encoding by angular












0















I'm using ngx-cookie-service a third party cookie service with angular 7.
i'm trying to set a cookie string like id=111&name=angular but angular change it to
id%3D111%26name%3Dangular.



import { CookieService } from 'ngx-cookie-service';
export class CookieComponent{
constructor(private cookieService: CookieService) {
this.setCookie();
}
setCookies() {
let cookieStr: string = "id=111&name=angular";
this.cookieService.set('cookieName', cookieStr);
//this set cookieName=id%3D111%26name%3Dangular in browser
}
getCookies() {
let cookie = this.userService.cookieService.get('cookieName');
//this returns cookieName=id=111&name=angular
}
}


but i need to get cookie from back end but c# does not automatically decode it but angular do.



now how to skip this default angular encoding for this cookie string










share|improve this question

























  • Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

    – Jitendra G2
    Jan 2 at 5:42











  • try setting your cookie with encodeURI("id=111&name=angular")

    – Tushar Walzade
    Jan 2 at 5:54











  • you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

    – Faisal
    Jan 2 at 5:58











  • @Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

    – Jitendra G2
    Jan 2 at 6:06













  • yes exactly what i want

    – Faisal
    Jan 2 at 6:07
















0















I'm using ngx-cookie-service a third party cookie service with angular 7.
i'm trying to set a cookie string like id=111&name=angular but angular change it to
id%3D111%26name%3Dangular.



import { CookieService } from 'ngx-cookie-service';
export class CookieComponent{
constructor(private cookieService: CookieService) {
this.setCookie();
}
setCookies() {
let cookieStr: string = "id=111&name=angular";
this.cookieService.set('cookieName', cookieStr);
//this set cookieName=id%3D111%26name%3Dangular in browser
}
getCookies() {
let cookie = this.userService.cookieService.get('cookieName');
//this returns cookieName=id=111&name=angular
}
}


but i need to get cookie from back end but c# does not automatically decode it but angular do.



now how to skip this default angular encoding for this cookie string










share|improve this question

























  • Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

    – Jitendra G2
    Jan 2 at 5:42











  • try setting your cookie with encodeURI("id=111&name=angular")

    – Tushar Walzade
    Jan 2 at 5:54











  • you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

    – Faisal
    Jan 2 at 5:58











  • @Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

    – Jitendra G2
    Jan 2 at 6:06













  • yes exactly what i want

    – Faisal
    Jan 2 at 6:07














0












0








0








I'm using ngx-cookie-service a third party cookie service with angular 7.
i'm trying to set a cookie string like id=111&name=angular but angular change it to
id%3D111%26name%3Dangular.



import { CookieService } from 'ngx-cookie-service';
export class CookieComponent{
constructor(private cookieService: CookieService) {
this.setCookie();
}
setCookies() {
let cookieStr: string = "id=111&name=angular";
this.cookieService.set('cookieName', cookieStr);
//this set cookieName=id%3D111%26name%3Dangular in browser
}
getCookies() {
let cookie = this.userService.cookieService.get('cookieName');
//this returns cookieName=id=111&name=angular
}
}


but i need to get cookie from back end but c# does not automatically decode it but angular do.



now how to skip this default angular encoding for this cookie string










share|improve this question
















I'm using ngx-cookie-service a third party cookie service with angular 7.
i'm trying to set a cookie string like id=111&name=angular but angular change it to
id%3D111%26name%3Dangular.



import { CookieService } from 'ngx-cookie-service';
export class CookieComponent{
constructor(private cookieService: CookieService) {
this.setCookie();
}
setCookies() {
let cookieStr: string = "id=111&name=angular";
this.cookieService.set('cookieName', cookieStr);
//this set cookieName=id%3D111%26name%3Dangular in browser
}
getCookies() {
let cookie = this.userService.cookieService.get('cookieName');
//this returns cookieName=id=111&name=angular
}
}


but i need to get cookie from back end but c# does not automatically decode it but angular do.



now how to skip this default angular encoding for this cookie string







angular cookies






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 7:45







Faisal

















asked Jan 2 at 5:27









FaisalFaisal

123118




123118













  • Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

    – Jitendra G2
    Jan 2 at 5:42











  • try setting your cookie with encodeURI("id=111&name=angular")

    – Tushar Walzade
    Jan 2 at 5:54











  • you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

    – Faisal
    Jan 2 at 5:58











  • @Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

    – Jitendra G2
    Jan 2 at 6:06













  • yes exactly what i want

    – Faisal
    Jan 2 at 6:07



















  • Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

    – Jitendra G2
    Jan 2 at 5:42











  • try setting your cookie with encodeURI("id=111&name=angular")

    – Tushar Walzade
    Jan 2 at 5:54











  • you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

    – Faisal
    Jan 2 at 5:58











  • @Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

    – Jitendra G2
    Jan 2 at 6:06













  • yes exactly what i want

    – Faisal
    Jan 2 at 6:07

















Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

– Jitendra G2
Jan 2 at 5:42





Can you show us? How did you set Cookie and how you are getting cookie value and output result? Provide some more details.

– Jitendra G2
Jan 2 at 5:42













try setting your cookie with encodeURI("id=111&name=angular")

– Tushar Walzade
Jan 2 at 5:54





try setting your cookie with encodeURI("id=111&name=angular")

– Tushar Walzade
Jan 2 at 5:54













you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

– Faisal
Jan 2 at 5:58





you mean like this this.cookieService.set('cookieName', encodeURI(cookieStr)); this doesn't work

– Faisal
Jan 2 at 5:58













@Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

– Jitendra G2
Jan 2 at 6:06







@Faisal You want to cookieName value "id=111&name=angular" instead of "id%3D111%26GUID%3Dangular" in browser?

– Jitendra G2
Jan 2 at 6:06















yes exactly what i want

– Faisal
Jan 2 at 6:07





yes exactly what i want

– Faisal
Jan 2 at 6:07












1 Answer
1






active

oldest

votes


















1














ngx-cookie-service doesn't provide optional to remove encode/decode feature.



As you can see in below screen shot, each request for cookie name and cookie value will be convert into encoded string.



cookie.service.js (node_modules/ngx-cookie-service/cookie-service)



enter image description here



There are two ways you can use,



1st,
I am not recommending this way but you can remove encodeURIComponent method.



      e.g. var cookieString = name + '=' + value + ';';


2nd, You can use WebUtility to decode in backed side (WebAPI).



      e.g. string cookieString = WebUtility.UrlDecode("id%3D111%26name%3Dangular");





share|improve this answer


























  • ok got it. it is not possible with ngx-cookie-service

    – Faisal
    Jan 2 at 7:17













  • Yes correct. Thanks

    – Jitendra G2
    Jan 2 at 7:26













  • but if edit the code like your first option will this work on server?

    – Faisal
    Jan 2 at 7:51











  • Did you tried? If you publish your code on your local IIS, It will work.

    – Jitendra G2
    Jan 2 at 8:01













  • on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

    – Faisal
    Jan 2 at 8:03













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001625%2fresolve-string-encoding-by-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














ngx-cookie-service doesn't provide optional to remove encode/decode feature.



As you can see in below screen shot, each request for cookie name and cookie value will be convert into encoded string.



cookie.service.js (node_modules/ngx-cookie-service/cookie-service)



enter image description here



There are two ways you can use,



1st,
I am not recommending this way but you can remove encodeURIComponent method.



      e.g. var cookieString = name + '=' + value + ';';


2nd, You can use WebUtility to decode in backed side (WebAPI).



      e.g. string cookieString = WebUtility.UrlDecode("id%3D111%26name%3Dangular");





share|improve this answer


























  • ok got it. it is not possible with ngx-cookie-service

    – Faisal
    Jan 2 at 7:17













  • Yes correct. Thanks

    – Jitendra G2
    Jan 2 at 7:26













  • but if edit the code like your first option will this work on server?

    – Faisal
    Jan 2 at 7:51











  • Did you tried? If you publish your code on your local IIS, It will work.

    – Jitendra G2
    Jan 2 at 8:01













  • on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

    – Faisal
    Jan 2 at 8:03


















1














ngx-cookie-service doesn't provide optional to remove encode/decode feature.



As you can see in below screen shot, each request for cookie name and cookie value will be convert into encoded string.



cookie.service.js (node_modules/ngx-cookie-service/cookie-service)



enter image description here



There are two ways you can use,



1st,
I am not recommending this way but you can remove encodeURIComponent method.



      e.g. var cookieString = name + '=' + value + ';';


2nd, You can use WebUtility to decode in backed side (WebAPI).



      e.g. string cookieString = WebUtility.UrlDecode("id%3D111%26name%3Dangular");





share|improve this answer


























  • ok got it. it is not possible with ngx-cookie-service

    – Faisal
    Jan 2 at 7:17













  • Yes correct. Thanks

    – Jitendra G2
    Jan 2 at 7:26













  • but if edit the code like your first option will this work on server?

    – Faisal
    Jan 2 at 7:51











  • Did you tried? If you publish your code on your local IIS, It will work.

    – Jitendra G2
    Jan 2 at 8:01













  • on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

    – Faisal
    Jan 2 at 8:03
















1












1








1







ngx-cookie-service doesn't provide optional to remove encode/decode feature.



As you can see in below screen shot, each request for cookie name and cookie value will be convert into encoded string.



cookie.service.js (node_modules/ngx-cookie-service/cookie-service)



enter image description here



There are two ways you can use,



1st,
I am not recommending this way but you can remove encodeURIComponent method.



      e.g. var cookieString = name + '=' + value + ';';


2nd, You can use WebUtility to decode in backed side (WebAPI).



      e.g. string cookieString = WebUtility.UrlDecode("id%3D111%26name%3Dangular");





share|improve this answer















ngx-cookie-service doesn't provide optional to remove encode/decode feature.



As you can see in below screen shot, each request for cookie name and cookie value will be convert into encoded string.



cookie.service.js (node_modules/ngx-cookie-service/cookie-service)



enter image description here



There are two ways you can use,



1st,
I am not recommending this way but you can remove encodeURIComponent method.



      e.g. var cookieString = name + '=' + value + ';';


2nd, You can use WebUtility to decode in backed side (WebAPI).



      e.g. string cookieString = WebUtility.UrlDecode("id%3D111%26name%3Dangular");






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 7:11

























answered Jan 2 at 7:05









Jitendra G2Jitendra G2

803612




803612













  • ok got it. it is not possible with ngx-cookie-service

    – Faisal
    Jan 2 at 7:17













  • Yes correct. Thanks

    – Jitendra G2
    Jan 2 at 7:26













  • but if edit the code like your first option will this work on server?

    – Faisal
    Jan 2 at 7:51











  • Did you tried? If you publish your code on your local IIS, It will work.

    – Jitendra G2
    Jan 2 at 8:01













  • on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

    – Faisal
    Jan 2 at 8:03





















  • ok got it. it is not possible with ngx-cookie-service

    – Faisal
    Jan 2 at 7:17













  • Yes correct. Thanks

    – Jitendra G2
    Jan 2 at 7:26













  • but if edit the code like your first option will this work on server?

    – Faisal
    Jan 2 at 7:51











  • Did you tried? If you publish your code on your local IIS, It will work.

    – Jitendra G2
    Jan 2 at 8:01













  • on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

    – Faisal
    Jan 2 at 8:03



















ok got it. it is not possible with ngx-cookie-service

– Faisal
Jan 2 at 7:17







ok got it. it is not possible with ngx-cookie-service

– Faisal
Jan 2 at 7:17















Yes correct. Thanks

– Jitendra G2
Jan 2 at 7:26







Yes correct. Thanks

– Jitendra G2
Jan 2 at 7:26















but if edit the code like your first option will this work on server?

– Faisal
Jan 2 at 7:51





but if edit the code like your first option will this work on server?

– Faisal
Jan 2 at 7:51













Did you tried? If you publish your code on your local IIS, It will work.

– Jitendra G2
Jan 2 at 8:01







Did you tried? If you publish your code on your local IIS, It will work.

– Jitendra G2
Jan 2 at 8:01















on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

– Faisal
Jan 2 at 8:03







on localhost this will definitely work but if i publish this to azure will the changes in package works? i think no because we never upload these node module files. how to make it work on server too?

– Faisal
Jan 2 at 8:03






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001625%2fresolve-string-encoding-by-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory