I am trying to redirect to a page from the server without referrer. Right now I am doing redirect like this:
I haven't found any overloads for Redirect method or any other ways to redirect without referrer so it's present on the page:
So is there any solution to redirect without referrer in ASP.NET?
You can't handle the referrer from the Redirect method, but you can do one of the following:
Launch the new page on a new window.
Using a meta tag on the content page as follows:
<meta name="referrer" content="no-referrer" />
Or you can add the tag following this answer: How to add meta tag to ASP.Net content page
Move the redirect logic to the front and use rel(attribute specifies the relationship between the current document and the linked document) use:
link
I think you're asking "after my C# server code sends a redirect to the client browser, telling it to go somewhere else, I want the browser to NOT put my site URL into the Referer header when it goes to that somewhere else"
You can't, if it's direct, unless you're redirecting from a secure page (yours) to an insecure page (theirs)
You'll probably have to create an interim page that you redirect to, that has some client side scripting that performs the actual transition (like those "thanks for searching your flight with expedia, please wait while we transfer you to the airline to complete your booking" type pages) because then you can take control of what their browser sends; if you straight refer them, you can't
Related
I develop an ASP.NET MVC application and I need to get url of youtube page, from user goes to my page. For example, on youtube.com under my video I put a link to my web-site. When user goes to my website I should receive link to youtube page. I try to receive this link using the next code:
Request.UrlReferrer
but when I go to my page from youtube.com the Request.UrlReferrer is null.
Also, note, that I click on my link on youtube.com page I go to my page thru page like:
https://www.youtube.com/redirect?q=http%3A%2F%2mysite.azurewebsites.net%2FHome%2FFillForm%3FFormID%3DbdHN7K9oFkQ&redir_token=tl-svjka0c6n2TVko3CXXXoDak18MTM5NzMyODMwMUAxMzk3MjQxOTAx
How can I get UrlReferrer value?
This is most likely caused by the fact that it's redirecting from an https URL to an http URL and the browser gets paranoid about security.
That said, the referer header is not guaranteed to be sent in any case and your logic can't depend on it being available.
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.
Here is my situation:
Page1.aspx redirects to Page2.aspx which does some processing (does not display to the user) and then redirects to Page3.aspx which checks the ServerVariables["HTTP_REFERER"] or Request.UrlReferrer.
I understand that the referring information can sometimes be blank and can't be entirely relied upon; however the ServerVariables["HTTP_REFERER"] or Request.UrlReferrer on Page3.aspx is showing Page1.aspx instead of Page2.aspx which I would have expected.
Does the referring information only get set if the page displays to the user?
Redirecting is done using Response.Redirect in order to change the URL in the address bar of the browser.
because the http redirect instructs the browser to find the page in a new place, so the browser assumes it's still dealing with the original request on page1.aspx, and hence sends that through as the referer :)
it's worth bearing in mind that the referer is just sent through from the browser and hence cannot be trusted 100% - some proxies remove it altogether for example.
I believe part of it depends on how the page is being redirected: Server.Transfer or Response.Redirect.
http://haacked.com/archive/2004/10/06/responseredirectverseservertransfer.aspx
I wanted to know if there is a solution using IIS6 for an application to get rid of the default.aspx text in the url. so for example if a user hits:
www.website.com/default.aspx
the browser only shows:
www.website.com/
No matter what.
It's just for SEO.
I already use UrlRewriting.NET for some rewrites in my app but for I'm not that clever to create a rule for that.
Any help is much appreciate.
Thanks.
Jose
I think ScottGu already has the topic of rewriting in ASP.NET covered: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx.
He covers things such as:
Rewriting using UrlRewriter.net, ISAPI Rewrite
ASP.NET Tricks, posting back (hitting the friendly version of the url)
With your problem I think you need to use a combination of, never linking to 'default.aspx' ie. ONLY link to '/'. Then use Scott's Form Postback browser file to ensure postbacks always hit that same friendly version of the url.
Redirecting 'default.aspx' to '/', which then gets served by 'default.aspx' sounds like a recipe for disaster to me. Just fix your links to ensure you never end up on 'default.aspx' explicitly.
I think the simplest way to change the search results index (assuming it knows about HTTP 301) is to write a little function in your default.aspx's Page_Load that redirects the browser using a 301 Moved Permanently (or 302 Moved Temporarily).
void Page_Load(...) {
if(Request.Path.EndsWith("default.aspx", true/*case-insensitive*/, null)) {
Response.StatusCode = 301;
Response.StatusDescription = "Moved Permanently";
Response.Headers.Add("Location", "/");
HttpContext.Current.ApplicationInstance.CompleteRequest(); // end the request
}
// do normal stuff here
}
If you have something to do URL rewriting, then all you need to do its ensure that your links point to the correct URL.
If you don't fix your links, its up to the browser to decide if it wants to display the actual link it requested.
If you would really like to do a dodgy job, you can use some javascript to make the address bar of the browser display whatever you like, even if its invalid.
If default.aspx is set as the default document to serve in IIS, and all your internal site links contain URL's without the default.aspx then I think that should do the trick.
Although the user can still type in default.aspx, search engine spiders should just pick up the friendlier URL's from your link href attributes.
The way I would do it is to use Application_BeginRequest in public class Global : System.Web.HttpApplication and check the HttpContext.Current.Request.URL for default.aspx, and then use HttpContext.Current.Response.Redirect from there if you find it.
The downside is having a redirect is not always so great and this isn't going to work if you are posting data to that default.aspx page. But you can't simply trick the browser into showing a different url, though you can tell ASP.NET to serve whatever page you want for any request.