简体   繁体   English

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

[英]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.

相关问题 为什么在定义mvc httppost时无法加载jquery? - Why does jquery load not work when mvc httppost is defined? 为什么MVC验证不适用于“&lt;”和“&gt;”? - Why does MVC validation not work for “<” and “>”? 当 WebApi 以单独的程序集托管在内存中时,DI 不起作用 - DI does not work when WebApi is hosted in memory in separate assembly MVC:为什么这可以用作表达式但不能用作代码块 - MVC: Why does this work as an expression but not as a code block 为什么MVC验证在我的代码中不起作用? - why mvc validation does not work in my code? 在WebApi端解析/使用MultipartFormDataContent(由MVC设置) - Parsing/Consuming a MultipartFormDataContent (set by MVC) on the WebApi side 与MVC相比,为什么JSON反序列化在MVC3中不起作用 - Why does this JSON deserialization not work in MVC3 compared to MVC 为什么提前输入不适用于此MVC5应用程序? - Why does typeahead not work for this MVC5 application? 为什么MVC JavaScript粘滞菜单仅在不使用URL中的/ controller / action时才起作用? - Why does MVC JavaScript Sticky Menu only work when not using /controller/action in URL? 当托管在Azure网站中时,除了App_Data之外,可以访问asp MVC网站中的哪个文件夹来存储和检索文件? - What folder in asp MVC Web Sites are accessible to store and retrieve files apart from App_Data when hosted in Azure Web Sites?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM