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.
Related
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 a .net C# page that redirects to an absolute url, eg:
Response.Redirect("rtsp://myvideoServer.com/myVideoAddress.mp4?ticket=1234&dt=1234");
But after the redirecting it results in:
"http://m.mysite.com/rtsp://myvideoServer.com/myVideoAddress.mp4?ticket=1234&dt=1234"
It works fine if I write the url to an HTML page and click the address. But the redirection does that mess.
The most weird is that it worked before last version.
Do you have any ideas? I'm almost doing a workaround to solve that.
Response.StatusCode = 301;
Response.AddHeader("location","rtsp://myvideoServer.com/myVideoAddress.mp4?ticket=1234&dt=1234");
Response.End();
EDIT is not working with browsers
I don't think a browser understands the rtsp protocol (in the meaning of doing e GET request in other way than from an embedded object), but if you have a client which understands this redirect, this should work.
I would suggest doing a workaround.
Use Response.AddHeader instead. It looks like Response.Redirect isn't recognizing rtsp:// as a protocol, and is treating it as a relative path.
Response.AddHeader("Location","rtsp://myvideoServer.com/myVideoAddress.mp4?ticket=1234&dt=1234");
I am trying to use domain masking to simulate multi-tenant access to my application. The plan right now is to read the subdomain portion of the domain ie: demo.mydomain.com and load settings from the DB using that name.
The issue I'm having is that request.url is getting the request url - NOT the url in the browser.
So if I have http://demo.mydomain.com forwarding to http://www.mydomain.com/controllername with masking, request.url is grabbing the latter, simply because of how masking works, i assume - by putting the masked site inside of a frame.
Is it even possible to read the url in the browsers address bar? Thanks.
You probably can get the url you want, but at the client side...
So, do this:
Get the browser's url by using a javascript call, like window.location.href.
Post that url to the server-side.
Cons:
This is a javascript dependent solution, it will not work with javascript disabled.
This is ugly as hell.
Pros:
You probably do not have any other option.
I'm using URL redirection in my site, so in this way one url like hotels.aspx?idh=34 becomes a SEO friendly hotels-from-aruba.h.aspx.
The problem is that I need for example refer the URL to facebook recommendation button or something like from server side code and when I use the request.url method I get again "hotels.aspx?idh=34" when the URL used to access the page was "hotels-from-aruba.h.aspx."
¿How can I get from server side the SEO friendly URL?
Thanks.
Use Request.RawUrl, that will be the URL the client requested (relative of course).
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