Tuesday, January 23, 2018

Redirect to login page if Idle Timeout is 10mins

MVC

The Following javascript file put in Layout Page(Views/Shared/_layout.cshtml ) on MVC page.

<script type="text/javascript">
        rootUrl = '@Url.Content("~/")';
        var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
           // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            window.location.href = '@Url.Action("Login", "Register")';

        }

        function resetTimer() {

            clearTimeout(t);
           // t = setTimeout(logout, 60000) //logs out in 1 min
         t = setTimeout(logout, 600000) //logs out in 10 min
        }


    </script>
================
Web Page(ASP.NET)

 The Following javascript file put on Master Page.(MasterPage.master) on ASP.NET Site

 <script type="text/javascript">
 var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
            // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            //window.location.origin : you'll get http://sub.domain.com *****
            window.location.href = window.location.origin+"/Account/login";

        }

        function resetTimer() {
            clearTimeout(t);
         //   t = setTimeout(logout, 60000) //logs out in 1 min
             t = setTimeout(logout, 600000) //logs out in 10 min

        }
    </script>

If no activity for 15 minutes, display an alert on web page, and then either continue or logout

This displays a jQuery dialog after 14 minutes of inactivity. If 15 minutes passes and no activity is found to be happening within the browser it is redirected to a logout URL:

// Set timeout variables.
var timoutWarning = 840000; // Display warning in 14 Mins.
var timoutNow = 900000; // Timeout in 15 mins.
var logoutUrl = 'http://domain.com/logout.aspx'; // URL to logout page.

var warningTimer;
var timeoutTimer;

// Start timers.
function StartTimers() {
    warningTimer = setTimeout("IdleWarning()", timoutWarning);
    timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
}

// Reset timers.
function ResetTimers() {
    clearTimeout(warningTimer);
    clearTimeout(timeoutTimer);
    StartTimers();
    $("#timeout").dialog('close');
}

// Show idle timeout warning dialog.
function IdleWarning() {
    $("#timeout").dialog({
        modal: true
    });
}

// Logout the user.
function IdleTimeout() {
    window.location = logoutUrl;

}


Add onload to your body tag calling StartTimers(). You can also add an onmousemove to the body tag which calls ResetTimer() so that as long as there is activity on the page a timeout is not triggered. If no mouse activity is seen on the page the dialog is displayed if movement is detected the dialog is closed and the timers reset.

<body onload="StartTimers();" onmousemove="ResetTimers();">
And the div used for the jQuery dialog:

<div id="timeout">
    <h1>Session About To Timeout</h1>
    <p>You will be automatically logged out in 1 minute.<br />
    To remain logged in move your mouse over this window.
</div>


Of course you can modify it to fit your needs and wants such as adding a button click which calls ResetTimers() if you dont want it reset when a mouse is moved over the browser but this should give you a starting point.

Monday, January 22, 2018

How to fix This site can't be reached error





Right click on your MVC Project. Go to Properties. Go to the Web tab.
Change the port number in the Project Url. Example. 
localhost:50645
Changing the bold number, 50645, to anything else will change the port the site runs under.
Press the 
Create Virtual Directory button to complete the process.


1.Image shows the web tab of an MVC Project 


2. rename Applicationhost configuration file



Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...