Reputation: 1535
I would like to access the url of the browser even before the page is loaded and replace it.
I just do not want the user to be able to watch on which page s/he is landing.
I though of accessing the url in Page_Init, but I can't find out how.
Any thoughts or better - solutions?
EDITED:
I do not need to change (or remove) the server name in the URL, only the folder/file name.
So, if the original page location is of the form: http://www.server.com/folder/file.aspx
I would like to change it to http://www.server.com/misc/GeneralPage.aspx
or http://www.server.com/
Response.Redirect will not do. I would like to stay at the same page, but to change the URL.
Server.Transfer is the default solution with a helper pre landing file, but it is not good enough for me. I would like to stay in the same page, but to change the displayed URL.
Solution:
There was an answer here involving HTML5 and one more solution direction, which I had in mind to investigate soon, but it is not here anymore (disappeared). If it was your answer, please write it once more. It was an important one.
I gave here the best option found as my decision of action (for now, until I'll find a better solution), but I do not take credit for it (I do not mark it as an answer). It is a detailed tested solution.
Upvotes: 1
Views: 2454
Reputation: 11
var stateObj = { foo: "bar" }; history.pushState(stateObj, "page 2", "bar.html");
you can use this code by creating java-script function and call it on clientclick event of a button
in place of bar.html just change to any of your url e.g. index.html and when you will click on button your output will be as follows i.e. www.dotnetprofessional.in/bar.html or www.dotnetprofessional.in/index.html without page getting post back or refresh
Upvotes: 0
Reputation: 1535
I'm giving here my decision for action (temporal). As soon as I'll decide on a better solution, I'll post it here with credit.
Although it is the solution I wished to avoid, it looks like it is the best there is for now.
After reading all answers and comments, the solution I decided on is to have an empty landing page and use Server.Transfer to the hidden file. I put the Server.Transfer in Page_Init.
The lading page Lading.aspx
contains one line only:
<%@ CodeFile="Landing.aspx.cs" Inherits="Landing" %>
It's code behind Landing.aspx.cs
contains:
using System;
public partial class Landing : System.Web.UI.Page
{protected void Page_Init(){Server.Transfer("~/Landing_Hidden.aspx");}}
The hidden page Landing_Hidden.aspx
is a regular aspx page.
Many thanks to everyone with answers and comments.
I find that in phishing view mentioned here, there is no difference using this above solution other than changing the URL.
Upvotes: 0
Reputation: 2799
For security reasons, you cannot change the entire URL in order to stop URL spoofing and thus phishing attacks.
You can, however, change any portion of the URL after the hash (#) sign. This portion of the URL is only available in client side javascript and can be used to store state information of the current page without reloading it. It is the windows.location.hash
property.
Upvotes: 1
Reputation: 34038
This is not possible due to browser security features. If the browser allowed programmers to display different URLs than what the user was actually on, then there would be a lot more people unknowingly handing over their sensitive banking information to third parties.
The URL is supposed to identify the specific resource that was requested by a browser and returned by the server.
With that said, there are domain masking tricks you can use at the Domain Management level. One technique used by GoDaddy is to foward your domain with masking, this essentially loads your website in an iframe so that the original URL is preserved at the original domain with the new content served up in an iframe.
You could also use this technique yourself. When you return content to the browser, return an iframe with the src attribute pointing to the new content.
Still, as far as modifying the actual URL displayed, this is not possible, and I'm not sure why you would really even want to do this.
Upvotes: 2