SamJolly
SamJolly

Reputation: 6477

How to pull apart a querystring in C# when # provided instead of?

I use .NET 4.7, MVC5, C#

I am receiving a querystring from 3rd party endpoint which has a # in it instead of a ? ie:

endpoint#code=123456&parm2=123....

instead of:

endpoint?code=123456&parm2=123....

My usual code of:

string[] codes = Request.Params.GetValues("code")

or

string code = Request.QueryString["code"];

will not deal with this. Keeps returning null. I am unable to get 3rd party to change this, apparently it is part of the oauth2 spec, something called a "hash fragment".

Is it possible to get the full returned url and pulled the relevant bit out via string handling routines?

While I cannot see the full URL in the debugger, if I let the endpoint complete, I see the full querystring with the # in it with the URL box of the browser. Wish I could get this in code to splice.

Thoughts?

Thanks in advance.

Upvotes: 1

Views: 124

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157098

The fragment (everything after the # sign) is not send to the server according to RFC 2396, section 4:

However, "the URI" that results from such a reference includes only the absolute URI after the fragment identifier (if any) is removed and after any relative URI is resolved to its absolute form.

There is no way to retrieve it server side.

Upvotes: 3

Related Questions