【问题标题】:ASP.NET UpdatePanel cause full postback after idleASP.NET UpdatePanel 在空闲后导致完全回发
【发布时间】:2013-08-30 07:29:46
【问题描述】:

我在我的 SharePoint 可视化 Web 部件中使用了多个更新面板。一切正常,直到我让页面闲置一段时间。

例如,如果我更改了几个下拉菜单并让页面闲置约 5 分钟。返回页面并更改下拉菜单将导致完整的回发。

另一个例子是使用带有分页的gridview。离开第 5 页的网格视图。闲置 5 分钟,然后返回页面。例如,单击第 8 页将使 gridview 转到第 1 页。

我是使用 Updatepanels 的新手,非常感谢一些建议。

【问题讨论】:

  • 你的会话过期时间设置是多少?
  • 我应该在哪里设置这个?在 sharepoint web.config 文件中?
  • Sharepoint Central 管理员 -> 应用程序管理 -> 配置会话状态
  • 我在 Sharepoint 2013 中找不到此设置

标签: asp.net updatepanel web-parts sharepoint-2013


【解决方案1】:

我通过添加这个 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>

如果此答案对您有帮助,请标记为答案...

谢谢..!!

【讨论】:

    【解决方案2】:

    在整个场中启用或禁用会话状态

    在任务栏上,单击“开始”,指向“管理工具”,然后单击“SharePoint 3.0 管理中心”。

    在顶部导航栏中,单击应用程序管理选项卡。

    在应用程序管理页面的 Office SharePoint Server 共享服务部分,单击配置会话状态。

    在“配置会话状态”页面的“启用会话状态”部分,选中“启用会话状态”复选框以启用场的会话状态。

    要指定会话的持续时间,请在“超时”部分的“会话应在(分钟)之后超时”框中输入一个数字(以分钟为单位)。默认为 60 分钟。

    点击确定保存会话状态配置。

    这个会给你更多的指导

    http://technet.microsoft.com/en-us/library/cc263527.aspx

    如果有任何困惑问我,

    【讨论】:

    • 问题标记为 Sharepoint-2013,此答案适用于 SharePoint-2007 (wss 3)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多