Как я могу перенаправить пользователя на страницу входа в систему по истечении определенного времени с использованием C# в ASP.NET?
I’m working on an ASP.NET program with the code behind in C# and connected to a SQL Server database. I want to create a timeout that sends them to the logout page after a certain number of minutes. I’m not using session timeout because the timeout value will vary based on the user’s role. The .aspx page has an UpdatePanel with a DetailsView that has a BoundField for the TimeOut in epoch seconds and another BoundField for the CurrentEpochSecond. These fields are from the database using a select statement. A second DetailsView contains a TemplateField that shows the TimeLeft using a SqlDataSource statement that selects the TimeOut minus the CurrentEpochSecond as TimeLeft. This is triggered by an AJAX timer every 60 seconds and the TimeLeft value is shown in the DetailsView.
Что я уже пробовал:
In the C# code I’ve tried several statements. When I put if (TimeLeft < 1) { Response.Redirect("~/Logout.aspx"); } VS shows an error that says: “The name 'TimeLeft' does not exist in the current context” When I define TimeLeft as an int and change it to int TimeLeft; if (TimeLeft < 1) { Response.Redirect("~/Logout.aspx"); } VS shows an error that says: “Use of unassigned local variable 'TimeLeft'”.