I am getting 400 bad request when provider hosted app is trying to connect to SharePoint.Below is the stacktrace:
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Project.SharePoint.Web.Controllers.HomeController.GetLoggedInUserName()
The server logs shows that /_vti_bin/client.svc/ProcessQuery is giving me 400 bad request.
I have tried to connect to the client.svc from browser of the server where the MVC provider is installed and it works, so there is no access issue. Any help would be great.
Edit:
[SharePointContextFilter]
public string GetLoggedInUserName()
{
string userName = string.Empty;
User spUser = null;
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
var web = clientContext.Web;
spUser = web.CurrentUser;
clientContext.Load(spUser, user => user.Title);
clientContext.ExecuteQuery();
userName = spUser.Title;
}
}
return userName;
}
HomeController.GetLoggedInUserName()
?SharePointHighTrustContextProvider
instead ofSharePointContextProvider
? It's a complete guess, I just remember seeing classes specific to acs and high trust the other day when I perused theSharePointContext.cs
file.