2

Basically I am trying to post data and redirect from one mvc application to another mvc application. I am NOT sending data through headers. Below is my code

 public ActionResult Translation()
    {

       string Url = "http://localhost/MVCWebApplication2/Home/Index";

       string sData = "some data"

       string res = PostData(Url, sData);

       return Redirect(Url);

    }

public static string PostData(string sURL, string sData)
    {
        string result = "";

        string _method = "POST";

        try
        {
            // prepare request
            HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(sURL);
            wreq.Method = _method;
            wreq.ContentType = "application/x-www-form-urlencoded";
            wreq.ContentLength = sData.Length;

            wreq.AllowAutoRedirect = true;
            wreq.MaximumAutomaticRedirections = 10;

           // post to server
            Stream sw = wreq.GetRequestStream();
            StreamWriter wr = new StreamWriter(sw);
            wr.Write(sData);
            wr.Close();


            // get response
            HttpWebResponse httpResponse = (HttpWebResponse)wreq.GetResponse();

            Stream sr = httpResponse.GetResponseStream();
            StreamReader rd = new StreamReader(sr);
            result = rd.ReadToEnd();
            httpResponse.Close();



        }
        catch (System.Exception ex) { return ex.Message.ToString(); }

        return result;
    }

Once the data is posted I am storing the data into Session, till this point it is working fine But after that I am redirecting it to that application then I am getting the Session Value as NULL, which is obvious ?

So, how can I post the data and redirect to the another application

Thanks for the help !

XamDev
  • 3,377
  • 12
  • 58
  • 97
  • Possible duplicate of [MVC Redirect with custom headers](http://stackoverflow.com/questions/18026050/mvc-redirect-with-custom-headers) – Baahubali Apr 22 '16 at 05:26
  • I would suggest storing your principle in database or third party cache. Redis would be a good option for you to look at. So you would set the logintoken and then after redirect you can set the principal back from the cache. – SadiRubaiyet Apr 22 '16 at 05:30
  • @SadiRubaiyet Exactly, that's what I am doing. When data is posted I am storing in cache for that particular client. Problem is on redirect How can I get the client name and by comparing it get data for that client. `string somedata = Request.Params["somedata"]; HttpRuntime.Cache[client] = somedata;` – XamDev Apr 22 '16 at 05:39
  • you can pass the logintokenid as a parameter and set a expired token on cache, then on the global.ascx try to read the cache, you can even do a fall back where you query the login table again and reauthenticate – SadiRubaiyet Apr 22 '16 at 05:46
  • @SadiRubaiyet Global.asax cannot be used, I am using MVC6 which do not have Global.asax – XamDev Apr 22 '16 at 05:50
  • oh, I am not that familiar with mvc 6, there could be something similar on startup.cs – SadiRubaiyet Apr 22 '16 at 06:02
  • 1
    Look here: http://stackoverflow.com/questions/3438912/share-session-between-two-web-sites-using-asp-net-and-state-server – Javi Apr 22 '16 at 19:08

0 Answers0