Search code examples
asp.net-mvcasp.net-mvc-4session-cookiessession-timeout

how to end session or logout a user on browser close MVC ASP .NET


I have designed a MVC Form and would like to end the session when user closes the browser and if re-open the browser, then has to log in again!

I don't know if I have to end session or clear cookies and if so, how should i do it. Will you help me to find my answer...

Thank you!


Solution

  • You can use:

    function del_cookie(name) {
        document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
    }
    
    <body onload="SetCookie()" onunload="del_cookie()">
    

    source here

    try modify it yourself