Using CookieContainer with HttpRequest class

48 Views Asked by At

I am working with HttpRequest class and i have two Action in my controller like below!

public class HomeController : Controller
{
   CookieContainer CookieContainer = new CookieContainer();

    public ActionResult Start()
    {
       var request = (HttpWebRequest)WebRequest.Create("www.sample.com");
       request.CookieContainer = viewModel.cookieJar;
       request.Method = "GET";
    }

    [HttpPost]
    public ActionResult Start (StartModel startModel)
    {
      var request = (HttpWebRequest)WebRequest.Create("www.sample.com/another");
      request.CookieContainer = viewModel.cookieJar;
      request.Method = "POST";
    }
}

I have a button on my view and its posts values getting my first actions response to second action's model. But Cookiecontainer is refreshes when enter the second action.

Well i have to send cookies came from first request to second request. How can i?

0

There are 0 best solutions below