Is there any way to show another page into your page? I cannot use frames, because frame will open that page directly, I want to copy the whole page and save it into new file, then show my new file to user. I think it is better to do this using a simple URL encryption because I don't like to show the real page address. For example, I want to use below URL instead of yahoo.com: www.myDomain.com/Open.aspx?url=zbipp_dpn ... I know how to read, encrypt and decrypt URL, but my problem is I don't know how to copy that page into new page and how to show that.
EDIT: I don't know how to start research even I don't know what should I looking for. This is the reason why I am asking my question here, from experts. I need a keyword to start research!
It sounds like you are trying to setup a proxy.
You could do the following:
Listen for requests using an HTTP handler. This can be an MVC controller, a web form (ASPX), an instance of
IHttpHandler
, even a raw TCP server.Use the encrypted URL to determine the target website.
Make a request from your website to the other website. There are multiple ways to do this in .Net, including the
HttpClient
class.Convert the response to a string.
(Optional) parse links in the content to point to your proxy website address instead of the real address.
Return the string to the caller as the body of the response. As far as their browser knows, it is the page they requested.
Disclaimer: While proxies are commonly used, there are potential implications (beyond my non-legal knowledge and advice) to presenting someone else's content under a different URL. In addition, there may be other (perhaps serious) ramifications to circumventing filtered content. Proxied content even with the modified URL may still trigger a filter.
Well, finally I started creating a web proxy.
I decided to explain my work here for two reasons: 1) For everyone who wants to start a similar project. 2) Most parts of these codes are copied from Stack pages, I've just collected them. ;)
I need experts to correct my mistakes and help me to continue.
Here is what I did:
ASP (Default.aspx):
I put a textbox named "txtURL" to enter the web address by user.
I put a button named "btnRun" to start processing.
For now, these components are enough!
C#:
Clicking on "btnRun", makes the page redirecting to: "www.domain.com/default.aspx?URL=(xxx)" - xxx will be replaced by web page address encrypted by a function.
This is the code for btnRun_Click:
I'll explain "Encrypt" and "ShowPopUpMsg" functions later.
By clicking on "btnRun", this page will be refreshed and the encrypted URL will be included in the address.
Now, in "Page_Load", we should read the encrypted URL (also a condition to detect postback):
From now, every code is added to "Page_Load", one after other.
Decrypt the URL and read the remote web page source-code:
I'll explain "Decrypt" and "GetHtmlPage" later.
Now, we have the source-code in "response".
Next step is find the links in this source-code. Begining of the links is "href="xxx"" and xxx is the link. We must replace them with our links through the proxy:
"SearchString" is a function to return the closing quotation mark of "href". I'll explain this later.
There are two kind of links:
Links that refer to another domain-name. This links are begun with "http://" or "https://". We'll find them and replace the address:
Link that refer to current domain-name. This links are begun with "/". To replace them, we should first find the domain name then the whole address:
Now, everything is done (refer to my current knowledge) and we should show the page with new links and finish "Page_Load":
Function to search in a string:
Function to read source-code:
Function to show a popup message:
Function to decrypt a string:
Function to encrypt a string: