当从kendo组合框读取ajax调用时如何处理会话超时

问题描述 投票:0回答:1

使用kendo组合框时如何处理会话超时?

下面是我的剑道组合框的html代码

@(Html.Kendo().ComboBoxFor(model => model.PropertyName)
                              .AutoBind(true)
                              .Suggest(true)
                              .DataTextField("Text")
                              .DataValueField("Value")
                              .DataSource(source =>
                              {
                                  source.Read(read =>
                                  {
                                      read.Action("ActionName", "ControllerName");
                                  })
                                  .ServerFiltering(true);
                              })
                              .Animation(false)
                              .Filter("contains")
                              .HighlightFirst(false)                              
                )

当在控制器会话超时中发生调用时的read.Action时发生,并且我编写了自定义属性来检查会话是否过期并使用以下代码返回403状态代码

if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                    {
                        filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Forbidden");
                        return;
                    }

然后使用以下代码在layout.cshtml页面中处理了此返回状态,然后重新加载该页面以转到登录页面

$.ajaxSetup({
        error: function (x, e) {
            if (x.status == 403) {
                window.location.reload();
            }
        }
    });

它适用于所有ajax请求,但不适用于来自kendo组合框的ajax请求。请帮助我在kendo combobox ajax请求时处理它。

c# jquery ajax kendo-asp.net-mvc
1个回答
0
投票

我已通过将complete事件放在ajaxsetup中解决了此会话超时问题。当响应来自kendo时,当时来自kendo的ajax请求发生时,它将不被视为错误,它称为完成事件,而不是称为错误事件,因此在将完整事件页面重定向到登录页面之后]

$.ajaxSetup({
        error: function (x, e) {
            if (x.status == 403) {

                window.location.reload();
            }
        },
        complete: function (x, e) {
            if (x.status == 403) {

                window.location.reload();
            }
        }
    });  

它按预期运行。

© www.soinside.com 2019 - 2024. All rights reserved.