ASP.NET UpdatePanel导致空闲后完全回发
我在SharePoint Visual Web部件中使用了多个UpdatePanel。在我让页面闲置一段时间之前,一切正常 例如,如果我更改了一些下拉列表,并让页面空闲大约5分钟。返回页面并更改下拉列表将导致完整的回发 另一个例子是使用带有分页的gridview。离开第5页的网格视图。空闲5分钟,然后返回页面。例如,单击第8页将使gridview转到第1页ASP.NET UpdatePanel导致空闲后完全回发,asp.net,updatepanel,web-parts,sharepoint-2013,Asp.net,Updatepanel,Web Parts,Sharepoint 2013,我在SharePoint Visual Web部件中使用了多个UpdatePanel。在我让页面闲置一段时间之前,一切正常 例如,如果我更改了一些下拉列表,并让页面空闲大约5分钟。返回页面并更改下拉列表将导致完整的回发 另一个例子是使用带有分页的gridview。离开第5页的网格视图。空闲5分钟,然后返回页面。例如,单击第8页将使gridview转到第1页 我不熟悉使用Updatepanels,非常希望得到一些建议。在整个服务器场中启用或禁用会话状态 在任务栏上,单击开始,指向管理工具,然后单击
我不熟悉使用Updatepanels,非常希望得到一些建议。在整个服务器场中启用或禁用会话状态 在任务栏上,单击开始,指向管理工具,然后单击SharePoint 3.0管理中心 在顶部导航栏中,单击应用程序管理选项卡 在“应用程序管理”页面的“Office SharePoint Server共享服务”部分中,单击“配置会话状态” 在“配置会话状态”页面的“启用会话状态”部分中,选中“启用会话状态”复选框以启用服务器场的会话状态 要指定会话的持续时间,请在“超时”部分的“会话应在(分钟)后超时”框中输入一个数字(分钟)。默认值为60分钟 单击“确定”保存会话状态配置 这个会给你更多的指导
如果有任何困惑,请询问我,在整个服务器场中启用或禁用会话状态 在任务栏上,单击开始,指向管理工具,然后单击SharePoint 3.0管理中心 在顶部导航栏中,单击应用程序管理选项卡 在“应用程序管理”页面的“Office SharePoint Server共享服务”部分中,单击“配置会话状态” 在“配置会话状态”页面的“启用会话状态”部分中,选中“启用会话状态”复选框以启用服务器场的会话状态 要指定会话的持续时间,请在“超时”部分的“会话应在(分钟)后超时”框中输入一个数字(分钟)。默认值为60分钟 单击“确定”保存会话状态配置 这个会给你更多的指导
如果有任何困惑问我,我已经通过添加此javascript解决了这个匿名问题。我发现,对于每个请求,经过一段理想的时间(约30秒)后,页面将转到“验证用户”。若用户并没有进行身份验证,那个么它会重新加载整个页面并重新验证用户,这就是页面重新加载的原因 在您的页面中添加此java脚本代码将解决您的问题
<script type="text/javascript">
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);
}
</script>
var isNtlmActive=false;
var updatePanelSoupDate=[];
var eventTarget='';
var eventArgument='';
var causesValidation=false;
var validationGroup='';
var requestBody='';
函数initializeRequestHandler(发送方,参数){
var onSuccess=函数(){
//此时,将重新建立NTLM连接
var pageRequestManagerInstance;
isNtlmActive=true;
pageRequestManagerInstance=Sys.WebForms.PageRequestManager.getInstance();
//重新发出“原始”请求
pageRequestManagerInstance.beginAsyncPostBack(UpdatePannelSoupDate、eventTarget、eventArgument、causesValidation、validationGroup);
};
var onError=函数(){
//如果发生错误,请在此处执行操作
}
如果(!isNtlmActive){
//捕获并保存主体以及关于原始请求的一些其他元数据
requestBody=args.get_request().get_body();
updatePannelsToUpdate=发件人。\u postBackSettings.panelsToUpdate;
eventTarget=sender.\u postBackSettings.asyncTarget;
eventArgument='';
causesValidation=false;
validationGroup='';
//注意:变量“\u spFormOnSubmitCalled”是一个全局变量,由“init.js”文件中实现的逻辑I注入。
//根据我们对'init.js'中逻辑的观察,当HTML表单
//“onsubmit”函数被调用,并且它永远不会被设置回false(在我们取消回发后)
//因此,任何后续提交表单的尝试都不起作用。
//因此,在取消最初的回发请求之前,我们不择手段地将该值设置回false。
//
//“init.js”由SharePoint自动引用,并包含在“母版”页面中。
//SharePoint还提供了HTML表单以及处理提交的功能。
if(类型为_spFormOnSubmitCalled==“布尔”){
_spFormOnSubmitCalled=false;
}
参数设置\取消(真);
调用ServerSideServiceToReviventLMSession(成功时,返回错误);
}
否则{
//使用从原始请求捕获的值重置请求主体
args.get_request().set_body(requestBody);
isNtlmActive=false;
UpdatePanelSoupDate=[];
eventTarget='';
eventArgument='';
causesValidation=false;
validationGroup='';
}
}
函数getCurrentSiteCollectionUrl(){
var-url;
url=window.location.protocol+“/”+window.location.host+_spPageContextInfo.siteServerRelativeUrl;
返回url;
}
函数CallServerSideServiceToReciventLMSession(successHandler,errorHandler){
var-siteCollectionUrl;
var-testServiceUrl;
var-spRequestExecutor;
var请求;
siteCollectionUrl=getCurrentSiteCollectionUrl();
testServiceUrl=siteCollectionUrl+“/\u api/web/t