We are finding HttpContext.Current.Request.Url.ToString() and HttpContext.Current.Request.UrlReferrer.ToString() values in an httpmodule. Is there any difference in getting the values from the normal page load?
Suppose if the request is coming from a google search result, then what will be the output of those two values.
HttpContext.Current.Request.Url points to the resource on your server while UrlReferrer is the URL which requested the resource.
if the request is coming from google search, UrlReferrer will give you google url something like http://www.google.com/search?q=[some text]
From MSDN (http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx):
Url: Gets information about the URL of the current request.
UrlReferrer: Gets information about the URL of the client's previous request that linked to the current URL.
Related
I'm using Asp.Net MVC. I want to know the url from which a request has been sent to my controller action.For example my controller action is(Customer/Index) and I want to get the url from which, my action is called.(I don't need the current URL).I want the source URL from which the request sent to me. Is there any solution?
You could try using url referrer e.g.
Request.UrlReferrer
Request.QueryString["Referrer"].ToString()
Have a look at this link: MDN reference
It states that "A Referer header is not sent by browsers if: The referring resource is a local "file" or "data" URI."
If you want to have that available if your page calls 'itself' i.e. another page/controller in you web application, you can try to add the header manually on a per request basis.
I am writing a code to get through authentication to a API based web site. I have the API key that the site needs during the login process. When I call the login method with the API key, it is supposed to redirect to a predefined URL whose parameter will then contain the request token.
e.g on firing the URL in the browser,
https://kite.trade/connect/login?api_key=hcwmefsivttbchla
I am redirected to
https://impacted-purposes.000webhostapp.com/?status=success&request_token=nb0vrfota9ott1r02q153pk3422joruf
(The request token will change in every run)
Notice the request token in the URL on the redirected URL. That's what I need to get from the code.
So, I use a the code that is referred here GetFinalRedirect:
Getting the Redirected URL from the Original URL
ie. I call:
GetFinalRedirect("https://kite.trade/connect/login?api_key=hcwmefsivttbchla")
However, I don't get the final redirect. I understand there could be a Javascript redirect, but checking the response, doesn't suggest so.
Any help pls to get the final URL so that I can parse the request token from it.
Well, I can't test this since i don't have an account. And I hope thats not your real-api-key...
But the function you're using is just sending a HEAD request to server. A HEAD request has no response. With the HEAD request you will only get redirects that are included in the HTTP headers. If the redirect is done with HTML-META tags or with javascript you have to send a GET (or POST) request...
If that fails too set a breakpoint inside the function and look at the received http-headers and the response text...
How to check using C# if "redirect" to "default document" happened?
For example, in browser I type URL: mysite.com/. When on server I check HttpContext.Current.Request.Url.AbsoluteUri, i receive mysite.com/default.aspx...
How I can get the exact URL that user has in his browser?
Thanks
EDIT: After some questions about the needs, I will give more details.
I have page with default.aspx with iframe inside of it. The iframe src is not the same origin (default.aspx is http and iframe content is https). On server side, i need to set the query string param to the src of iframe to include the exact URL that user has in browser. I need it in order to be able to set parent.location = parentURL + '#myparam' on iframe client side.
Currently everithing works fine, except when the request made to domain name without providing file name.
Try HttpContext.Current.Request.RawUrl
You typed
mysite.com/.
and you get
mysite.com/default.aspx...
Because you have set default.aspx as the default / Start up page in your site. The browser always redirect to the default page. I think when we type mysite.com the asp.net automatically appends the default page in the URL, so when we use Request.Url we get the mysite.com/default.aspx
Reading your intention of the IFrame, perhaps you are looking for Framset Script to determine the redirection ?
if (parent.location.href==window.location.href)
{
// you re-direction codes...
}
EDIT :
Giving a different HTTP and HTTPS, it's likely the Same Origin Policy kicked in. There is a workaround you could use PostMessage interface for cross sites.
Other option would be managed by Server(IIS) so that both http/https url request setting to default document , so that you don't need to alter client-side scripting for such complication handling.
You should delete 'Default.aspx' page from your IIS Default document list. then you get exact URL that user entered.
I have two website
1) Main website: it has a link Help & Training that redirects user to another Help website.
2) Help website has no authentication rules thus anybody can visit the website directly.
Now I have a requirement to allow second website to be visited from first website's link, all the other request should be redirect to another page.
Offcourse querystring/parameter validation is not acceptable as that can be visible and constant
Is it possible, any suggestion is appreciated.
You can use http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx which is just an ASP.NET wrapper around the HTTP referrer header. http://en.wikipedia.org/wiki/HTTP_referrer
This, of course, can be spoofed so don't rely on it for creating something super secure.
what if you add a get parameter to the link's url in the first site and checks for it in the second site. That's of course a very simple solution and could be cheated pretty fast.
from here:
You could use the UrlReferrer property of the request:
Request.UrlReferrer
This will read the Referer HTTP header from the request which may or may not be supplied by the client (user agent).
Hi you can use this block of code to identify from where the user came to your website
If Not IsPostBack Then
If Not Request.UrlReferrer.ToString() Is Nothing Then
referrer = Request.UrlReferrer.ToString()
End If
End If
if you want something that's not easily spoofable by average users...
site2 exposes a webservice which validates a "secret" parameter (could just be some long random string that only site1 and site2 know). this service returns a unique "token" that is only good for a small period of time. site1 appends this token to the querystring when directing the user to site2. site2 validates that the token is legit and still valid. once a token has been used, site2 no longer treats it as valid.
Duplicate:
Finding previous page Url
How do I find the referring url that brought a user to my site in ASP.NET?
See Also:
How can I find what search terms (if any) brought a user to my site?
Request.UrlReferrer
But this isn't guaranteed to be correct or even exist.
Request.UrlReferrer can be used to retrieve the previous page url from where the current page has been redirected.
The referer URL should be in the HTTP headers on the request.
E.g. Uri MyUrl = Request.UrlReferrer
See: http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx
Request.UrlReferrer
http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx
HttpContext.Current.Request.UrlReferrer