如何使用MVC Web应用程序中的服务器端代码重定向到远程服务器上的网站?

时间:2022-04-22 15:34:16

I am trying to create an ASP.NET MVC web application which connects to a certain website, which I will call website1, on a certain server, which I will call server A, and from this server the user is able to connect to another website, which I will call website2, on a different server, which I will call server B. Server B and any website therein is only accessible from Server A so the redirect from website1 to website2 must be done using server side code. The user needs to be able to initiate the connection to website2 using something similar to a button or a hyperlink.

我正在尝试创建一个ASP.NET MVC Web应用程序,它连接到某个网站,我将其称为website1,在某个服务器上,我将其称为服务器A,并且从该服务器,用户可以连接到另一个网站我将在不同的服务器上调用website2,我将其称为服务器B.服务器B及其中的任何网站只能从服务器A访问,因此必须使用服务器端代码完成从website1到website2的重定向。用户需要能够使用类似于按钮或超链接的东西来启动与website2的连接。

I am aware that code within a code block of a view which is denoted by @ does run on the server side, but I cannot get code like this to be called in response to user interaction.The OnClick() handler for the <a></a> tag does not let me call a helper method of the view which might run on the server and neither does @Html.ActionLink(). I can call a method of the controller using @Html.ActionLink("caption","method name") though I cannot figure out how to write server side code here which will connect me to website2. Server.Transfer does not work because this only works for redirecting to pages on the same server. Response.Redirect is also out because this uses the client's browser through which server B and website2 would not be accessible.

我知道,由@表示的视图的代码块中的代码确实在服务器端运行,但是我不能在响应用户交互时调用这样的代码。的OnClick()处理程序标签不允许我调用可能在服务器上运行的视图的辅助方法,也不会调用@ Html.ActionLink()。我可以使用@ Html.ActionLink(“caption”,“方法名称”)来调用控制器的方法,虽然我无法弄清楚如何编写服务器端代码,这将把我连接到website2。 Server.Transfer不起作用,因为这仅适用于重定向到同一服务器上的页面。 Response.Redirect也出局,因为它使用客户端的浏览器,通过该浏览器无法访问服务器B和网站2。

I would greatly appreciate any direction on resolving this matter as I do not quite know where to go from here. I have been doing searches extensively but have seen nothing which seems to fit with my situation. Please let me know if I have missed anything and I will gladly check it out.

我非常感谢解决这个问题的任何方向,因为我不知道从哪里开始。我一直在广泛地进行搜索,但没有看到任何符合我情况的东西。如果我错过了什么,请告诉我,我很乐意检查出来。

1 个解决方案

#1


0  

You can use this anywhere in your controller:

您可以在控制器的任何位置使用它:

Response.Redirect("http://www.anyserveryoulike.org");

For example, in the action you reach with your:

例如,在您使用以下内容执行的操作中:

@Html.ActionLink("caption","method name")

#1


0  

You can use this anywhere in your controller:

您可以在控制器的任何位置使用它:

Response.Redirect("http://www.anyserveryoulike.org");

For example, in the action you reach with your:

例如,在您使用以下内容执行的操作中:

@Html.ActionLink("caption","method name")