0

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?

Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
confusedMind
  • 2,573
  • 7
  • 33
  • 74

4 Answers4

1

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];
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • This still requires further processing, the `Fragment` property will return *everything* after the `#` so the OP would still need to parse the string. I do think the preferred method for this sort of scenario is to use `ParseQueryString`. – James Apr 26 '13 at 11:44
  • Yeah i think javascript and ajax is the straight way! – confusedMind Apr 26 '13 at 11:46
  • @Thank you for the idea i used javascript and ajax to get it done! – confusedMind Apr 29 '13 at 04:17
0

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"];
James
  • 80,725
  • 18
  • 167
  • 237
  • How does that work on the server side? For a value after the `#`? – Oded Apr 26 '13 at 11:36
  • The OP states the URL is *returned* from the an api server, it doesn't mention anything about that URL being the current request. – James Apr 26 '13 at 11:37
0

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

Community
  • 1
  • 1
Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
0

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!

kapsiR
  • 2,720
  • 28
  • 36