简体   繁体   English

将数据从ASPX页面发布到MVC页面

[英]Post data from aspx page to mvc page

I am trying to post data from one page (aspx) to another (mvc). 我试图将数据从一页(aspx)发布到另一页(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: 我试图解决的方法是在(aspx.cs)后面的代码中,但是到目前为止,我发现成功重定向的唯一方法是使用:

 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). 我不能使用它,因为它显然只能使用GET(这将不起作用,因为我要传输的数据可能包含太多字符,无法处理GET)。 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. 但是我不确定如何在其他mvc控制器Index方法中读取该数据。

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. 这是假设您要以编程方式从后面的代码中进行POST。

Session wouldn't work going from one web app to another. 从一个Web应用程序转到另一个Web应用程序,会话将无法工作。 It only works from one page to another in the same site. 它只能在同一站点中从一页到另一页使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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