user3847663
user3847663

Reputation: 1

MVC Redirect from one project to another in one solution

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

Thanks in advance,

Upvotes: 0

Views: 9621

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038880

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.

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.

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");

Upvotes: 4

Related Questions