1

I have asp.net web site, for registered users.

In the login page, I use ajax call for authentication. the call can return url of home page, or other string of error.

code:

 $.ajax({
    type: 'POST',
    async: true,
    data: "{'userName':'" + $("#txtUserName").val() + "'" + ",'password':'" + $("#txtPassword").val() + "','rememberMe':'" + $("#cbRemember").prop('checked') + "'}",
    contentType: 'application/json; charset=utf-8',
    dataType: "json",
    url: "Login.aspx/LoginSite",
    success: function (result) {
        if (/^Home.aspx/.test(result.d.url)) {
            location = result.d.url;
        }
        else {
            setMsg(result.d.success, result.d.msg, "loginMsg");
        }
    },
    error: function (arg1, arg2, arg3) {
        setMsg(false, "שגיאה בלתי צפויה", "loginMsg");
    }

There is a problem, that when user is in Login page, and 15 minutes of session passed, he has to refresh page. if he does not refresh, he get message of error, because there is no access to server.

So I change EnableSessionState to False.

But now I have another problem:

in the ajax call, after authentication the user, I want to insert his Id to session, but because of the EnableSessionState="False", Session throws an exception.
what can I do? maybe there is another way to implement ajax login in asp.net?

8
  • So what you want if 15 minutes are passed in login page you want to refresh the page automatically ? Jun 2, 2016 at 9:17
  • thanks for reply. can you show me how to do it in code? because I tried some ways to do it and it did not eork. Jun 2, 2016 at 9:18
  • Do you want to do what i have said in comments ? Jun 2, 2016 at 9:20
  • 1
    setTimeout(function () { location.reload(); }, 60 * 1000 * 15); Jun 2, 2016 at 9:29
  • 1
    You may be loosing session early in production enviornment that' why it may not be working Jun 2, 2016 at 9:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.