locked
asp.net core session time out issue RRS feed

  • Question

  • User1997618745 posted

    Dear Team, 

    We have an asp.net core application configured with azure b2c. 

    The problem what we are facing is when we keep the application idle for more than one hour and try to post the data using jquery ajax call we are getting an un authorized error. 

    How to handle this scenario. Please advice..

    Thanks 

    Wednesday, August 28, 2019 3:33 PM

Answers

All replies

  • User-474980206 posted

    the asp.net core app should return a not authorized error to the ajax call, and the client code should login in again.

    var dataPromise = fetch(url, {
      method: 'POST', 
      body: JSON.stringify(data),
      headers:{
        'Content-Type': 'application/json'
      }
    }).then(function(response) {
        if (response.status >= 200 && response.status < 300) {
           return (/^application\/json/.test(response.headers.get("content-type")))
             ? response.json();
             : response.text();
        } else if (response.status == UnauthorizedStatus) {
            // handle login
        } else
            // handle standard error
        }
    });
    



     

    Wednesday, August 28, 2019 4:09 PM
  • User1997618745 posted

    Thanks for your answer.

    Can you please advice How do I login from java script with out asking user to login again & this post also should also happen.

    We are using Azure b2c with out application. 

    Wednesday, August 28, 2019 4:16 PM
  • User-474980206 posted

    if their login expires, they need to login again, its the only way to get a token. you could use a long lasting renewal token, that the server stores (not in session), and renew the ticket via the renewal token. 

    Wednesday, August 28, 2019 5:12 PM
  • User711641945 posted

    Hi Selvakumar,

    For default lifetime for token is 60 minutes, after idle for more than one hour, the token will be invalid for the next time, I suggest you try to increase the lifetime by following link below:

    #Configure token lifetime

    https://docs.microsoft.com/en-us/azure/active-directory-b2c/configure-tokens#configure-token-lifetime

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2019 6:41 AM