0

I am having issues with post a form to MVC, but only when the site is hosted inside of azure. When it is hosted locally inside of IIS OR inside of the compute emulator it works fine.

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:

--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]
4
  • What error are you getting? Commented Oct 30, 2013 at 21:57
  • Good question, I forgot to add that. Commented Oct 30, 2013 at 22:06
  • It doesn't map the fields in the posted form to parameters on the action. Commented Oct 30, 2013 at 22:07
  • In fact, it appears to not parse the from at all as the posted fields do not appear in RequestContext.HttpContext.Request.Params. Commented Oct 30, 2013 at 22:11

1 Answer 1

3

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

Basically, you have to quote your param names:

data.Add(new StringContent(displayName), @"""displayName""");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.