MVC重定向从一个项目到另一个在一个解决方案 [英] MVC Redirect from one project to another in one solution

查看:378
本文介绍了MVC重定向从一个项目到另一个在一个解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以重定向从一个MVC项目到另一个在相同的溶液中,然后传递参数不用将它们扔网址是什么?

How can i redirect from one MVC project to another in the same solution and then passing parameters without passing them throw url ?

由于提前,

推荐答案

在部署应用程序不再有概念,如解决方案或项目。你只能做一个重定向到一个相对或绝对URL。相对URL将是相同的Web应用程序的一部分,所以你可以重定向到相应的控制器动作:

Once the application is deployed there are no longer notions such as solutions or projects. You can only make a redirect to either a relative or absolute url. A relative url would be part of the same web application so you could redirect to the corresponding controller action:

return RedirectToAction("SomeAction", "SomeController");

如果您需要重定向到另一个应用程序需要应该使用绝对网址:

If you need to redirect to another application you need should use an absolute url:

return Redirect("http://localhost:1234/SomeController/SoneAction");

显然,对于这个工作,其他应用程序需要在网络服务器来启动并主持。

Obviously for this to work the other application need to be started and hosted in a webserver.

至于传递参数而言一个GET请求是通过他们作为查询字符串键值对当由HTTP协议定义的标准方法。假设其他应用程序在同一域中的源应用程序,你也可以设置一个cookie的值可以通过目标应用程序可以读取主办。

As far as passing parameters is concerned the standard way defined by the HTTP protocol when making a GET request is to pass them as key value pairs in the query string. Assuming that the other application is hosted on the same domain as the source application you could also set a cookie whose value can be read by the target application.

下面是如何设置一个cookie的例子重定向前:

Here's an example of how you can set a cookie before redirecting:

var cookie = new HttpCookie("cookieName", "someValue")
cookie.Domain = ".example.com";
Response.SetCookie(cookie);
return Redirect("http://example.com/SomeController/SoneAction");

这篇关于MVC重定向从一个项目到另一个在一个解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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