请注意,我已尝试在Handling session timeout in ajax calls上应用该解决方案,但对我没有用。
在ASP.NET MVC5项目中,我通过AJAX渲染部分视图来打开页面,如下所示:
function renderPartial(e, controller, action) {
var controllerName = controller;
var actionName = action;
if (String(actionName).trim() == '') {
return false;
}
if (typeof (controllerName) == "undefined") {
return false;
}
var url = "/" + controllerName + "/" + actionName;
$.ajax({
url: url,
data: { /* additional parameters */ },
cache: false,
type: "POST",
dataType: "html",
error: function (jqXHR, textStatus, errorThrown) {
var message = errorThrown;
if (jqXHR.responseJSON != null) {
message = jqXHR.responseJSON.message;
}
},
success: function (data) {
var requestedUrl = String(this.url).replace(/[&?]X-Requested-With=XMLHttpRequest/i, "");
if (typeof (requestedUrl) == "undefined" || requestedUrl == 'undefined') {
requestedUrl = window.location.href;
}
// if the url is the same, replace the state
if (typeof (history.pushState) != "undefined") {
if (window.location.href == requestedUrl) {
history.replaceState({ html: '' }, document.title, requestedUrl);
}
else {
history.pushState({ html: '' }, document.title, requestedUrl);
}
}
//Load partialview
$("#div-page-content").html(data);
}
});
};
另一方面,当会话超时并通过超链接调用此方法时,在partialview字段上有一个空的白页,应该呈现部分视图页面。那么,有可能:
1)在此字段中显示部分视图?
2)重定向用户登录页面?
注意:如果您建议在ASP.NET MVC中处理会话过期的智能方法,我也会很高兴。提前谢谢......