ThorstenHans / ama

Ask me Anything - Keep questions and answers organized
https://www.xplatform.rocks
0 stars 0 forks source link

Provider Hosted App with Asp.NET MVC SPhostUrl missing while uploading image #1

Closed wasifmuneer closed 7 years ago

wasifmuneer commented 7 years ago

I am trying to create a simple post in which I am also attaching an image using Provider Hosted App on Sharepoint online, and I am not able to get SPHostUrl at Controller in HttpContext.Request, I mean SPHostUrl is missing in HttpContext.Request. [HttpPost] public ActionResult Contact(SimplePostModel model,HttpPostedFileBase file) {}

View

@using (Html.BeginForm("Contact","Home",null,FormMethod.Post,new { enctype= "multipart/form-data"})) The question is if I am sending this part new { enctype= "multipart/form-data"} in the above mentioned statement of View, I am not able to get SPHostUrl parameter in HttpContext.Request.

If I am not sending the html attributes then I am able to get SPHostUrl parameter in HttpContext.Request. and without html attributes I am also not able to upload a file.

Thanks in Advance for your help.

wasifmuneer commented 7 years ago

I have solved the issue,by changing some piece of code on in the Razor View.

`@using (Html.BeginForm("Contact","Home",null,FormMethod.Post,new { enctype= "multipart/form-data"}))`

Instead of null for object route values I send the spHosturl like below.

@using (Html.BeginForm("Contact","Home",new { SPHostUrl = spUrl },FormMethod.Post,new { enctype = "multipart/form-data" }))

the spUrl value comes like below

  @{
    var spUrl = Request.QueryString["SPHostUrl"];
}

I hope this will help for new sharepoint online developers