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
Related
If I have page located for example in
http://hostname.com/website_folder/page1.aspx
and from page in internal folder, I want to redirect to the above page
For example from these pages:
http://hostname.com/website_folder/folder1/folder2/page2.aspx
or
http://hostname.com/website_folder/folder1/folder2/folder3/page2.aspx
Try to use Response.Redirect(your url); in your code behind page. if you like to know more read here http://support.microsoft.com/kb/307903
I assume whenever the request comes for the below urls
http://hostname.com/website_folder/folder1/folder2/page2.aspx
http://hostname.com/website_folder/folder1/folder2/folder3/page2.aspx
you want to perform a permanent redirect to http://hostname.com/website_folder/page1.aspx.
This can be achieved by URL Mapping/Rewrite
There are several approaches explained by Scott Guthrie and also check How to specify url mappings in ASP.NET 4.0 when parameters are involved?
Hope this would help you
I have an asp.net C# website its url is like abc.com so when the website is loaded for the first time its url that appears is abc.com
But when i visit any other page and come backs to the home page its url become abc.com/home.aspx.
But i want it to be the same i.e abc.com means i want that the url that appears when the website is loaded for the first time and the url that appears for the home page after visiting any other page should be same.
I think url rewriting will be used here but i am not sure neither i have any knowledge how to use it so please help.
By default this happens because of Default Document feature.. You can read about more from http://www.iis.net/learn/web-hosting/web-server-for-shared-hosting/default-documents link.
However once you open us the website abc.com and when you navigate it will surely show you the page name like www.abc.com/home.aspx
And thus what you are looking for seems not possible.
You can use link tag marking the canonical in the header of the page. So, in abc.com/home.aspx you can generate the link tag that tells crawlers that this is a duplicate of abc.com and dont crawl it.
Here are more reference regarding the same subject:
http://www.seomoz.org/blog/which-page-is-canonical
http://guyellisrocks.com/coding/adding-a-canonical-link-element-in-asp-net/
If you see your home page when you visit abc.com it looks like your default page is set in place.
You can easily redirect user to "/" and it probably will be enough
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 need to retrive the Url of an application that is iframed...
What I have is an application that iframes another application.
For the application that's iframed I would like to retrive its Url, my question is now...
would Request.Url for the application thats iframed return the iframed applications url (the url thats in the src of the "main-application") or would it return the browser adress?
Just wanted to double check this with you guys.
Thanks in advance!
The Request.Url will return the iframe's Url.
If for some reason you want the Url of the page that contains the iframe, try using Request.UrlReferrer instead.
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.