为什么在Azure中托管MVC时,MultipartFormDataContent不起作用?

时间:2013-10-30 21:43:01

标签: asp.net-mvc asp.net-mvc-4 azure

我遇到将表单发布到MVC的问题,但只有当站点在azure中托管时才会出现问题。当它本地托管在IIS内部或计算模拟器内部时,它可以正常工作。

请求已发布,但表单中的字段未映射到操作的参数。

在天蓝色部署中我需要做些什么时髦吗?

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);

在服务器端,一切似乎都正确到达。这是我从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--

标题是:

ALL_RAW - Content-Length: 880
Content-Type: multipart/form-data; boundary="614f8827-0cfe-48a6-a819-e6e9acdccae0"
Host: [my server]

1 个答案:

答案 0 :(得分:2)

请参阅:How to upload files to Asp.Net MVC 4.0 action running in IIS Express with HttpClient class included in .Net 4.0

基本上,你必须引用你的参数名称:

data.Add(new StringContent(displayName), @"""displayName""");