Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am accessing my Mvc web application over a network, when network disconnected for some reason and again connected , i am able to access the page where i left. But i want to implement the scenario when network disconnected and again connected instead of continuing the webpage where it left , it will show the Login Page.
Please help me how to implement it
Posted

I can't claim it to be best/perfect idea but you can give it a try-

1. Add a hidden field to keep status of intenet disconnection status. Make sure that upon first call the value is set to "true" which means client is still connected to the internet.
ASP.NET
<asp:hiddenfield id="hfInternetDisStatus" runat="Server" value="True" xmlns:asp="#unknown"></asp:hiddenfield>

2. As you need to check this from client side, so Javacript is a good option. We need to run a timer in javascript and inside the timer funtion we need to write the logic for checking if inetrnet is disconnected.
Function For Internet Connectivity Check
JavaScript
<script type="text/javascript">
function CheckInternetConnection() {
  var status = navigator.onLine;
  var hfInternetDisStatus=document.getElementById("  <%=hfInternetDisStatus.ClientID%>");
  if (!status) {     
     hfInternetDisStatus.value="Flase"
  }
  //if you want to autoredirect to login page once internet is available
  //if(status && hfInternetDisStatus.value=="False")
  //{
       //window.location="Login.aspx";
  //}
}
</script>

Function for timer
JavaScript
<script type="text/javascript">
function StartMyTimer()
{
   setInterval(function () {CheckInternetConnection()}, 1000);
}
</script>


3. Set the timer
HTML
<body onload="StartMyTimer();" />


Either you can redirect the user to the login page once internet is available after disconnection which is illustrated in the commented code or if you want to redirect the user if he/she ineracts with the page then the redirect to login page should go in your respective/common method based upon the value contained in the hidden field.

I haven't executed any of the code snippets, this just an idea to start with. You may need to add/modify the code as per your requiremet.

Hope, it helps :)
 
Share this answer
 
v4
The internet works at layers above the network connection, so this isn't going to be technically possible to do...not without something on the client that keeps a permanent connection to the server, and that's a bad thing. The internet was specifically designed so that it can do this very thing....go on working when a connection goes down, so you're looking to implement something that goes directly against what the protocols were designed to achieve, so you're going to struggle.

This sounds to me like one of those pointless requirements people dream up, and rather than looking for a solution you should instead ask why this is a requirement in the first place.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900