U
U
Uran_902015-07-06 10:01:52
ASP.NET
Uran_90, 2015-07-06 10:01:52

How to parse url in asp.net mvc?

Good afternoon. Help, please with a problem. When authorizing via the VKontakte api, a redirection occurs to a url of the form: " localhost:58821/Auth # access_token= 123456712345123451234512345 &expires_in=0&user_id=1234567"
Calling Request.Url.AbsolutePath, Request.Url.AbsoluteUri or Request.RawUrl gives only a link to the host Request.RawUrl . How can I get parameters from given url?
Upd.: Probably the problem is that the address and get parameters are separated by '#', not '?', so the parameters cannot be obtained. Is there any way to get the whole string?
Upd. -code:

public class HomeController : Controller  
   {  
     private readonly AuthorizationRoot _authorizationRoot;  
     private const string ProviderNameKey = "providerName";  
     private string ProviderName  
     {  
       get { return (string)Session[ProviderNameKey]; }  
       set { Session[ProviderNameKey] = value; }  
     }  
     public HomeController(AuthorizationRoot authorizationRoot)  
     {  
       _authorizationRoot = authorizationRoot;  
       mVkProvider = new VkProvider();  
     }  
     public ActionResult Index()  
     {  
       var model = _authorizationRoot.Clients.Select(client => new LoginInfoModel  
       {  
         ProviderName = client.Name  
       });  
       return View(model);  
     }  
     /// <summary>  
     /// Redirect to login url of selected provider.  
     /// </summary>      
     public RedirectResult Login(string providerName)  
     {  
       ProviderName = providerName;  
       var client = GetClient();  
       string url = client.GetLoginLinkUri();  
       url = url.Replace("response_type=code", "response_type=token");  
       RedirectResult redirectResult = new RedirectResult(url);  
       return redirectResult;  
     }  
     /// <summary>  
     /// Renders information received from authentication service.  
     /// </summary>  
     public ActionResult Auth()  
     {  
       string fragment = Request.Url.Fragment; // fragment = ""  
       OAuth2Client client = (OAuth2Client)GetClient();  
       var userInfo = client.GetUserInfo(Request.QueryString);  
       mVkProvider.AccessToken = client.AccessToken;  
       JObject res = mVkProvider.SearchReferences("Test");  
       return View(userInfo);  
     }  
     private IClient GetClient()  
     {  
       return _authorizationRoot.Clients.First(c => c.Name == ProviderName);  
     }  
   }  
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sivabur, 2015-07-06
@sivabur

stackoverflow.com/questions/659887/get-url-paramet...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question