[英]Why does MultipartFormDataContent not work when MVC is hosted in Azure?
I am having issues with post a form to MVC, but only when the site is hosted inside of azure. 我将表单发布到MVC时遇到问题,但只有当站点在azure中托管时才会出现问题。 When it is hosted locally inside of IIS OR inside of the compute emulator it works fine. 当它在IIS内部托管或在计算模拟器内部时,它可以正常工作。
The request is posted, however the fields in the form are not being mapped to the action's parameters. 请求已过帐,但表单中的字段未映射到操作的参数。
Is there something funky I need to do with the azure deployment? 是否有一些我需要做的天蓝色部署?
MultipartFormDataContent data = new MultipartFormDataContent();
if (!String.IsNullOrEmpty(about))
{
data.Add(new StringContent(about), "about");
}
data.Add(new StringContent(displayName), "displayName");
data.Add(new StringContent(name), "name");
data.Add(new StringContent(email), "email");
data.Add(new StringContent(phone), "phone");
data.Add(new StringContent(isPublic ? "true": "false"), "isPublic");
data.Add(new StringContent(isPrimary ? "true" : "false"), "isPrimaryProfile");
if (picture != null)
{
byte[] imageBytes = await picture.GetBtyeFromFile();
string imageString = Convert.ToBase64String(imageBytes);
data.Add(new StringContent(imageString), "picture");
}
Uri uri = new Uri(url, UriKind.Absolute);
HttpResponseMessage responseMessage = await client.PostAsync(uri, data);
On the server side everything seems to be arriving correctly. 在服务器端,一切似乎都正确到达。 Here is the body that I pulled out of the InputStream: 这是我从InputStream中拉出的主体:
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=displayName
display
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=name
Test Seller Account
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=email
email
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=phone
phone
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=isPublic
false
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=isPrimaryProfile
true
--614f8827-0cfe-48a6-a819-e6e9acdccae0--
And are the headers: 标题是:
ALL_RAW - Content-Length: 880
Content-Type: multipart/form-data; boundary="614f8827-0cfe-48a6-a819-e6e9acdccae0"
Host: [my server]
See: How to upload files to Asp.Net MVC 4.0 action running in IIS Express with HttpClient class included in .Net 4.0 请参阅: 如何使用.Net 4.0中包含的HttpClient类将文件上载到在IIS Express中运行的Asp.Net MVC 4.0操作
Basically, you have to quote your param names: 基本上,你必须引用你的参数名称:
data.Add(new StringContent(displayName), @"""displayName""");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.