简体   繁体   中英

Post data from aspx page to mvc page

I am trying to post data from one page (aspx) to another (mvc). The way I am trying to go about it is in the code behind (aspx.cs) but so far the only way I have found to successfully redirect is to use:

 Response.Redirect

which I can't use this because it apparently can only use GET (which won't work because the data I am wanting to transfer can potentially have too many characters for GET to handle). The other stipulation is that I can't use a session variable (the person I'm working with refuses to use session data).

I've looked into things like:

var tdd = new TempDataDictionary();
tdd.Add("subject",subject);

and

Context.Items["subject"] = subject;

but I'm not sure how I'd read that data in the other mvc controller Index method.

Use...

var data = //byte[] containing your data to post
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
using (Stream requestStream = request.GetRequestStream())
{
    request.ContentLength = data.Length;
    requestStream.Write(data, 0, data.Length);
}

This is assuming you want to programmatically POST from the code behind.

Session wouldn't work going from one web app to another. It only works from one page to another in the same site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM