.net MVC:如何隐藏真实的URL? [英] .net MVC:How to hide the true URL?

查看:118
本文介绍了.net MVC:如何隐藏真实的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部URL,例如 http://a.com/?id=5(不在我的项目中)并且我希望我的网站显示此URL的内容,

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,

例如我的网站( http://MyWebsite.com/?id=123 )显示了第三方的网址( http://a.com/?id=5 )内容

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

但是我不希望客户端获得真实的URL( http://a.com/?id = 5 ),我将首先检查AUTH,然后显示该页面.

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.

推荐答案

我假设您无法控制" http://a.com/?id=5 ",然后将其返回给您的用户: ASP.NET MVC-使用cURL或类似于在应用程序中执行请求:

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:

我假设请求" http://a.com/?id=5 "位于GET方法中:

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;
}

然后,您只需要在控制器中调用它即可.从客户端传递相同的userAgent,以便他们可以像使用Web浏览器打开网站一样完全查看网站:

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:我可能没有使用正确的MVC API,但是想法就存在了.只需在HttpWebRequest上查找MVC文档即可使其正常工作.

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.

这篇关于.net MVC:如何隐藏真实的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆