0

I have an external URL, like http://a.com/?id=5 (not in my project) and I want my website to show this URL's contents,

ex. My website(http://MyWebsite.com/?id=123) shows 3rd party's url (http://a.com/?id=5) contents

but I don't want the client side to get a real URL(http://a.com/?id=5), I'll check the AUTH first and then shows the page.

Steven Chou
  • 1,504
  • 2
  • 21
  • 43

1 Answers1

1

I assume that you do not have control over the server of "http://a.com/?id=5". I think there's no way to completely hide the external link to users. They can always look at the HTML source code and http requests & trace back the original location. One possible solution to partially hide that external site is using curl equivalent of MVC, on your controller: after auth-ed, you request the website from "http://a.com/?id=5" and then return that to your user: ASP.NET MVC - Using cURL or similar to perform requests in application:

I assume the request to "http://a.com/?id=5" is in GET method:

public string GetResponseText(string userAgent) {
  string url = "http://a.com/?id=5";
  string responseText = String.Empty;
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.Method = "GET";
  request.UserAgent = userAgent;
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    using (StreamReader sr = new StreamReader(response.GetResponseStream())) {
       responseText = sr.ReadToEnd();
    }
 return responseText;
}

then, you just need to call this in your controller. Pass the same userAgent from client so that they can view the website exactly like they open it with their web browsers:

return GetResponseText( request.UserAgent); 
 //request is the request passed to the controller for http://MyWebsite.com/?id=123

PS: I may not using the correct MVC API, but the idea is there. Just need to look up MVC document on HttpWebRequest to make it work correctly.

Community
  • 1
  • 1
minhhn2910
  • 488
  • 4
  • 18
  • A important thing is I must to replace the static file's relative path with absolute path. – Steven Chou Dec 30 '16 at 04:44
  • 1
    Yeah, i forgot to mention that. If the webpage has static resources like images, js files, css files, we have to modify the paths before returning it to user. An alternative way (i think it's the better way in case the external site always use relative path) is to download these resources to your website as static resources and completely hide the external website – minhhn2910 Dec 30 '16 at 07:34