Hi,
How to identify if the first page of the website is refreshed in the same tab or the page is loading at the first time in asp.net mvc. If the page is opened in the different browser or tab, it should show an alert message and close the browser/tab.
Shweta LodhaPosted Sep 9, 2024, 12:05 AM
Here are the 2 ways:
Aman GuptaPosted Sep 7, 2024, 5:52 PM
Hi Anu,
If you are trying to identify if a page in ASP.NET MVC is being refreshed or if it's being loaded for the first time (in the same tab or a new tab/browser), you can use a combination of server-side and client-side techniques.
The basic idea is to track whether the page has been previously visited in the same session or not.
You can find it using Session, localStorage, and JavaScript:
Steps:
Example:
Controller (ASP.NET MVC):
View (Razor View
Index.cshtml):Explanation:
This will help you Anu, in detecting First Login or refreshed login.
Thanks
Uday DodiyaPosted Sep 7, 2024, 9:14 AM
Hi, Anu
you can achive both output like for Detecting Page Load or Refresh & Show Alert and Close Tab if Page is Opened in a New Tab/Browser using sessionStorage.
Add this JavaScript code in your MVC View (demo.cshtml )