Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wasifmuneer opened this issue Jan 10, 2017 · 1 comment

Comments

@wasifmuneer
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant