Hi,
We also ran into the described issue. We ended up creating the following work around solution.
The solution details
The main goal of the implemented solution was to ensure that NTLM connection is established before UpdatePanel submits a request.
To achieve this goal we implemented the following components:
- a JavaScript function that asynchronously calls one of the SharePoint's out of the box web services and effectively re-establishes NTLM connection (if it was lost)
- a JavaScript function that intercepts any postback request from any of the update panel on the page and cancels that. But in order to later re-issue the request, this function also captures and preserves the required metadata about the request
right before the request is canceled
- a JavaScript function that reissues the request after we ensure that NTLM connection is up and ready
Below is the complete JavaScript code that performs the described above actions
Code
<<
var isNtlmActive = false;
var updatePannelsToUpdate = [];
var eventTarget = '';
var eventArgument = '';
var causesValidation = false;
var validationGroup = '';
var requestBody = '';
function initializeRequestHandler(sender, args) {
var onSuccess = function () {
//At this point the NTLM connection is re-established
var pageRequestManagerInstance;
isNtlmActive = true;
pageRequestManagerInstance = Sys.WebForms.PageRequestManager.getInstance();
// re-issuing the 'original' request
pageRequestManagerInstance.beginAsyncPostBack(updatePannelsToUpdate, eventTarget,
eventArgument, causesValidation, validationGroup);
};
var onError = function () {
// do something here if error occurred
}
if (!isNtlmActive) {
// capturing and preserving the body as well as some other meta data about the original request
requestBody = args.get_request().get_body();
updatePannelsToUpdate = sender._postBackSettings.panelsToUpdate;
eventTarget = sender._postBackSettings.asyncTarget;
eventArgument = '';
causesValidation = false;
validationGroup = '';
// NOTE: the variable '_spFormOnSubmitCalled' is a global variable that gets injected by the logic iplemented in the 'init.js' file.
// Based on our observation of the logic in 'init.js' the varialbe '_spFormOnSubmitCalled' is set to true when HTML form's
// 'onsubmit' function is called and it is never set back to false (after we cancel the postback)
// As the result, any subsequent attempts to submit the form do not work.
// Thus, we excplicetely set the value back to false before we cancel the original post back request.
//
//'init.js'is autoatically referenced by SharePoint and included on to the 'master' page.
// The HTML form as well as the functionality to handle submit is also provided by SharePoint.
if (typeof _spFormOnSubmitCalled === "boolean") {
_spFormOnSubmitCalled = false;
}
args.set_cancel(true);
callServerSideServiceToReviveNtlmSession(onSuccess, onError);
}
else {
// resetting the body of the request with the value captured from the original request
args.get_request().set_body(requestBody);
isNtlmActive = false;
updatePannelsToUpdate = [];
eventTarget = '';
eventArgument = '';
causesValidation = false;
validationGroup = '';
}
}
function getCurrentSiteCollectionUrl() {
var url;
url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
return url;
}
function callServerSideServiceToReviveNtlmSession(successHandler, errorHandler) {
var siteCollectionUrl;
var testServiceUrl;
var spRequestExecutor;
var request;
siteCollectionUrl = getCurrentSiteCollectionUrl();
testServiceUrl = siteCollectionUrl + "/_api/web/title";
spRequestExecutor = new SP.RequestExecutor(siteCollectionUrl);
request = {
url: testServiceUrl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
};
spRequestExecutor.executeAsync(request);
}
try {
$(document).ready(function () {
try {
var pageRequestManagerInstance = null;
//Note: Sys.WebForms.PageRequestManager gets injected into your page the minute you use ScriptManager (and UpdatePanel)
pageRequestManagerInstance = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManagerInstance.add_initializeRequest(initializeRequestHandler);
}
catch (ex) {
//alert('INNER EXCEPTION: document ready - ' + ex.message);
}
});
}
catch (ex) {
//alert('EXCEPTION: document ready - ' + ex.message);
}
>>
As a prerequisite for the code above, You must have references to the following JavaScript files(libraries)
- jQuery
- <script src="/_layouts/15/SP.RequestExecutor.js" type="text/javascript"></script>
Based on my observations (in Development using Google Chrome), after implementing the solution the undesired behavior does not occur. Meaning, SharePoint does not cause redirection to the login page when UpdatePannel control submits a partial(async)
"post back".
Best Regards