In general, I put this in global.asax
protected void Application_BeginRequest(object sender, EventArgs e) { var context = new HttpContextWrapper(Context);
and for IsAjaxRequest() used this
public static bool IsAjaxRequest(this HttpRequestBase request) { if (request == null) { throw new ArgumentNullException("request"); } var context = HttpContext.Current; var isCallbackRequest = false;// callback requests are ajax requests if (context != null && context.CurrentHandler is Page) { isCallbackRequest = ((Page)context.CurrentHandler).IsCallback; } return isCallbackRequest || request["X-Requested-With"] == "XMLHttpRequest" || request.Headers["X-Requested-With"] == "XMLHttpRequest"; }
therefore, for all request forms, ajax auth will no longer be redirected. This is the best solution I have found.
And, optionally, put this in the client code to reload the page after receiving responses to error 401.
$(document).ajaxError(function (xhr, props) { if (props.status === 401) { location.reload(); } });
klonni Sep 04 '15 at 7:49 2015-09-04 07:49
source share