3

I have this code:

var search = $location.search();
    if (angular.isDefined(search.load) && search.load != null) {
        if (search.load = "confirmEmail")
            authService.confirmEmailUserId = search.userId;
            authService.confirmEmailCode = search.code;
            $state.transitionTo("auth.content", {
                content: search.load
            });
    }

It's in the app.run and it looks at the URL used to open the app.

But search.code was encoded with the C#

 var callbackUrl  = "http://localhost:2757/index.html" +
                    "?load=email" +
                    "&userId=" + user.Id +
                    "&code=" + HttpUtility.UrlEncode(code);

How can I get back the original value of code before it was passed to UrlEncode?

2
  • 1
    Using JavaScript: decodeURIComponent(). Commented Jan 16, 2015 at 12:52
  • @AndreiV - Can you put this as an answer so I can accept it please. Commented Jan 16, 2015 at 15:11

1 Answer 1

4

You could use the decodeURIComponent() JavaScript function. This function takes as parameter an URL encoded string and returns its unencoded form.

In your case, you could either decode the entire URL

var search = decodeURIComponent($location.search());

or just the code part

authService.confirmEmailCode = decodeURIComponent(search.code);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.