I am implementing google login on my site.
Problem is that when google redirect me back to my site (after confirmation) I can't get access token from query string.
This is URL:
http://localhost/mysite/west/Default.aspx#state=/profile&access_token=ya29.qQDrtcVtgOEbS86Bg10puFG3dksJz74BlrEGulHldlJW2o5qQ6g7ilF17zQsm8iMLG0C82PQyp2Z-g&token_type=Bearer&expires_in=3600
I suspect that this #state=/profile make some issue but can't handle it.
Am I missing something?
If URL is like this , note that there is # after Default.aspx , it is not ?, then there is no direct way to get get querystring ( they are known as URL fragments not querystring), they are meant to be parse at client side and server side don't have access to URL Fragments.
http://localhost/mysite/west/Default.aspx#state=/profile&access_token=ya29.qQDrtcVtgOEbS86Bg10puFG3dksJz74BlrEGulHldlJW2o5qQ6g7ilF17zQsm8iMLG0C82PQyp2Z-g&token_type=Bearer&expires_in=3600
Link contains # ,means an anchor, a position, on a webpage. The browser sends a GET request to the server containing only the address of the entire page, with no anchor, fragment or whatever. When the server returns the page, the browser knows where to position it so the location of the anchor is visible. In clientside or Javascript it is possible as it has access to the anchor.
Read this - How to get Url Hash (#) from server side
You could use
document.URL to get the url.
Then split the url by #state=/profile&
Then the second part of the array split by &.
Then each section split by first =
There may be a more elegant solution but this should work.
Related
My URL is: http://localhost/myApp/app/job/7#/Nmbr
When I tried to get the URL from HttpContext.Request or HttpContext.Current.Request,
the given url is : /myApp/app/job/7
# and everything after this letter are missing? Why? How can I get the real current url?
Http requests do not include anything after # (The browser does not send it with the request.)
# Is intended to allow for parameters to be specified for the browser only (Anchor target location, or with often with web 2.0 JavaScript parameters)
In order to pass parameters to the server use ? that appears before the #
Here is some information regarding fragments (The part of the URL after #)
The Fragment property gets any text following a fragment marker (#) in the URI, including the fragment marker itself. Given the URI http://www.contoso.com/index.htm#main, the Fragment property would return #main.
https://msdn.microsoft.com/en-us/library/system.uri.fragment(v=vs.110).aspx
I'm using Response.Redirect to to refresh a page with a parameter appended to the end of the URL but for some reason the parameter is being moved to a different part of the URL.
Here's an example, my URL is http://domain.com/en/members/careers/vacancies/?output=html
I want this URL to refresh with the following:
http://domain.com/en/members/careers/vacancies/?output=html¶m=1
I want to include the extra parameter so I used the following function:
string url = CurrentPage.LinkURL;
Response.Redirect(url+"?output=html¶m=1");
Yet when the page refreshes it has redirected to the following URL:
http://domain.com/en/?output=html/members/careers/vacancies/
I have no idea why the the output parameter is being put there after /en/ or where my second parameter has gone.
I've been at this for a few hours and I'm going crazy looking at it, any suggestions on this would be greatly appreciated. Thanks!
Maybe try this instead of CurrentPage.LinkURL. Also in you Response.Redirect take out the "?output=html" as it will already be in your string
string URL = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
Response.Redirect(URL + "¶m=1");
I want to parse webpage with Fragment identifier(#), f.e. http://steamcommunity.com/market/search?q=appid%3A570+uncommon#p4
When i use my browser(Google Chrome), i have different result, for different identifier(#p1,#p2,#p3), but when i use HTML Agility Pack, i always get first page, despite of page identifier.
string sURL = "http://steamcommunity.com/market/search?q=appid%3A570+uncommon#p"
wClient = new WebClient();
html = new HtmlAgilityPack.HtmlDocument();
html.LoadHtml(wClient.DownloadString(sURL+i));
I understand, that something like Ajax used here and in fact exist only one page. How can i fix my problem, and get results from other pages using C#?
Like David said,
use URL : http://steamcommunity.com/market/search/render/?query=appid%3A570%20uncommon&search_descriptions=0&start=30&count=10
where start is the start number and count is the number of items you want.
the result is a json result, so for stating the obvious you only want to use results_html
side note: in your chrome browser (when pressed F12) click on network tab and you will see the request and result being made
I need to parse url that has something after # (hash) sign in my asp.net application. How to do it easily?
Thank you,
You're looking for the Uri class:
new Uri(someString).Fragment
Note that the hash is not sent to the server in an HTTP request.
url.Substring(url.IndexOf('#') + 1)
...where "url" is a string containing the url in question
This is called "hash sign" URI.
After client gets PAGE responsed including js,
the contents after '#' would be handled by client using responsed js to get "real" URL for redirection.
SEE: https://www.w3.org/2001/tag/2011/01/HashInURI-20110115#References
Omg, I meant fragment (after #) part on the server... Though I've looked thrugh and found that it seems to be impossible......
I have a web-browser in a win form application and I am experiencing issues when opening a URL.
The URL I pass in as a new URL instance is encoded with:
/ as %2f , ? as %3f and the
= as %3d
But when I debug my code I can see that the absolute URL or any of the other ones in the webbrowser.url.* is decoded as / , ? and =.
How do I keep the URL encoded? The URL will not work if It is not encoded like that.
I found a solution to my problem, when you have a URL that looks something like this:
domain.com/action/doaction/?identity=12354698789
And you want it encoded like this:
domain.com/logon?returnurl=action%2fdoaction%2f%3fidentity%3d12354698789
That does not work in your web browser. It decodes it to the first url.
I needed the id in the doaction controller so I used this code:
string orgId = ControllerContext.RouteData.Values["id"].ToString();
It returns that url, if unsure, debug and trace through, you will find the right key and value.
Why is it a problem?
If you want the undecoded URL, use the HttpRequest.RawUrl Property. The query string is automatically decoded by default and there is no public parameter that would turn it off.