Resolve string encoding by angular
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

|
show 2 more comments
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

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 withencodeURI("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
|
show 2 more comments
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

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


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 withencodeURI("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
|
show 2 more comments
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 withencodeURI("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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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)
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");
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
|
show 3 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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");
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
|
show 3 more comments
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)
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");
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
|
show 3 more comments
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)
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");
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)
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");
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
|
show 3 more comments
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
|
show 3 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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