I have an application where around 20 http generic handler
are used for ajax call
.
I have used IReadOnlySessionState
for accessing the session in my handlers.Everything is working fine.
But when session expires my handler is returning some html as it redirects to default page and html of default page is sent back in the response.
To overcome this issue.
I have checked the session variable in the handler and if it is null the I have written
context.Response.Write("logout")
And I check in jQuery ajax weather it is logout or anything else.
$.ajax({
url: "myhandler.ashx",
contentType: "application/json; charset=utf-8",
success: function (data) { checklogout(data); $("#loading").hide(); },
error: function () { $("#loading").hide(); },
async: false
});
If it is logout then I have used location to redirect to login page.
I am using form-authentication
to authenticate user.
Is there any better approach for checking and redirecting to login page using jquery-ajax call.
$.ajaxsetup
), so the code to check only needs to go in one place. Is that along the lines of what you are seeking? – Shrum