Extract access token from the URL RRS feed

  • Question

  • I need to extract the access_token from the below URL. Home is the ControllerName and MSAuthorize is the action name to which after a User logs in into login.live.com is redirected to. Now I am inside the MSAuthorize method and i need to access the access token value in the URL, How to do it?:






    Note : There is a # before access_token in the URL due to which i am not able to access it in the query parameters
    • Edited by Tanmoy Paul 08 Wednesday, December 20, 2017 1:07 PM
    • Moved by Fei Hu Thursday, December 21, 2017 5:33 AM ASP.NET related
    Wednesday, December 20, 2017 1:06 PM

All replies

  • The simplest approach, in my opinion, is to simply do a string search on the url fro #access_token=. Then grab everything after that until &.

    Another approach, if you know this is the only #, is to use Replace to switch the # to a ? and then use Uri to parse it out.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 20, 2017 2:38 PM
  • But how do i access the URL when i am inside the redirected method i.e the URL...I tried System.Web.HttpContext.Current.Request.Url.ToString(); but it dosen't read anything after #.
    Wednesday, December 20, 2017 2:57 PM
  • Questions related to MVC should be posted in the ASP.NET forums.

    The Request object has the raw URL.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 20, 2017 3:03 PM