MVC Redirect from one project to another in one solution

后端 未结 1 1551
清酒与你
清酒与你 2021-01-28 05:21

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,

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-28 05:41

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

    0 讨论(0)
提交回复
热议问题