【发布时间】:2013-10-30 21:43:00
【问题描述】:
我在向 MVC 发布表单时遇到问题,但仅当网站托管在 azure 中时。当它本地托管在 IIS 内部或计算模拟器内部时,它可以正常工作。
请求已发布,但表单中的字段未映射到操作的参数。
我需要对 azure 部署做些什么?
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]
【问题讨论】:
-
你遇到了什么错误?
-
好问题,我忘了补充。
-
它不会将已发布表单中的字段映射到操作上的参数。
-
事实上,它似乎根本不解析 from,因为发布的字段没有出现在 RequestContext.HttpContext.Request.Params 中。
标签: asp.net-mvc asp.net-mvc-4 azure