I am new to MVC development, however, I current have a requirement to build an application for a SharePoint app. It is currently hosted on our Azure server and is up and running fine. My problem lies in interacting with SharePoint via the Controller.
I can retrieve data when the page is initially loaded, the problem is when I interact with the page, the Controller cannot seem to validate its connection with SharePoint. I have a button on the page that when clicked, goes off to SharePoint to retrieve some data and then populates a textbox on the page. To do this, I am making an AJAX request, in which I pass the Controller and the procedure (along with the SPHostUrl and SPAppWebUrl). It executes the procedure fine, but consistently returns a null value on the line:
spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext)
(i.e. spContext is always null) I cannot seem to retrieve the clientcontext from here.
Here is my AJAX request is that is of any help, but could someone point me in the right direction with this? Is there some level of authentication I need from a HttpGet request that I also need, or is there something I am simply missing?
$.ajax({
url: '@Url.Action("CalculateHolidayTime", "Holidays", new { @SPHostUrl = @ViewBag.SPHostUrl, @SPAppWebUrl = @ViewBag.SPAppWebUrl }, null)',
type: 'GET',
dataType: 'json',
cache: false,
data: { intEmployeeId: empId, strHolidayFrom: dateFrom, strHolidayTo: dateTo },
success: function(oTime) {
console.log("data call succeeded...");
$('#txtTotalTime').val(oTime.TotalTime);
alert(oTime.Output);
alert(oTime.Validation);
},
error: function(request) {
console.log("data call failed...");
alert(request.responseText);
}
});
EDIT: I have narrowed it down a little more, the HttpContext.Session doesn't contain any keys on the button click, specifically the "SPContext" key, which is used to hold the SharePoint context information. Any reason as to why the session loses its keys?