I have some Kendo MVC grids bound to remote Json controller actions which work very well. The MVC application uses a custom AuthorizeAttribute for authorizing access to the controller actions and when a user is not authenticated it replies with a 302 redirect to the login page. Everything is fine, except that when the session expires, the datasource read calls fail silently as they receive the redirect response instead of the expected data. I have tried handling this situation in the error event handler of the datasource, but the handler does not get called in this situation.
This is the error handler:
function childGrid_error(e, gridName) {
if (e.xhr.status === 302)
location.reload();
else
if (e.errors) {
var message = "";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
kendoAlert(message);
var grid = $(gridName).data("kendoGrid");
grid.cancelChanges();
}
}
And this is a Kendo Datasource, in Razor syntax:
.DataSource(ds => ds
.Ajax()
.Model(m => m.Id(c => c.Id))
.Sort(s=>s.Add(f=>f.Username))
.PageSize(10)
.Events(e => e.Error("function(e) { grid_error(e, \"UsersGrid\");}"))
.Read("GetUsers", "Admin")
.Create("PutUser", "Admin")
.Destroy("DeleteUser", "Admin")
.Update("UpdateUser", "Admin"))
Is there something I'm missing regarding this error handler?