confusedMind
confusedMind

Reputation: 2653

How to get # value in query string from a URL coming from an API, not the current request

I get a returned url from using facebook api:

http://www.example.com/#access_token=BAAGgUj7asdasdasdasda4z3cBAFD5ZAyTOMIxtBpjIHsNwLfZC6L9gZAIdSIt3bKP96rg7yAlplMBDA9ZCndAKS9a7m4oRmRmJAxSdCueefweWJrlq3vQv3XaGqTOLofEMjJIVNCYZD&expires_in=0

But i am not sure how to get the token value? As its not in query string or Request.url

Any help?

Upvotes: 0

Views: 409

Answers (4)

Oded
Oded

Reputation: 499092

You can't, assuming this is passed in on the current request, as anything after the # is never sent to the server.

You can capture it in JavaScript and use AJAX to send it to the server, but this will be on a different request.


If you mean you have this URL not from the current request, you can use the Uri class to parse a full URL and get the fragment:

var fragment = new Uri(theUri).Fragment;
var token = fragment.Split(new [] {'&','='}, StringSplitOptions.None)[1];

Upvotes: 1

kapsiR
kapsiR

Reputation: 3177

You have to look for "%23", because "#" is url-encoded to "%23"

reference: http://www.w3schools.com/tags/ref_urlencode.asp

But you have to know also, that anchors are not available on server side!

Upvotes: 0

Hassan Mokdad
Hassan Mokdad

Reputation: 5902

Check this Retrieving Anchor Link In URL for ASP.Net

you cannot get it from the server side, you will need to take if from client side first then pass it to the server in a hidden field or something similar

Upvotes: 0

James
James

Reputation: 82096

You can use HttpUtility.ParseQueryString to parse the URL then you can get the value by name e.g.

NameValueCollection query = HttpUtility.ParseQueryString(querystring);
string token = query["token"];

Upvotes: 0

Related Questions