locked
PREVENT USERS FROM LOGGING IN RRS feed

  • Question

  • For a silverlight web client is there an easy way to prevent users from logging in after hours?

    Isahak

    Thursday, July 7, 2016 5:10 PM

Answers

  • Open a screen and then click Write Code -> _CanRun to create the Application.cs. Delete the _CanRun partial method.

    Implement an Application_Initialize partial method as follows to check a time range and close the app is not valid:

    using Microsoft.LightSwitch.Threading;
    using System;
    using System.Windows;
    
    namespace LightSwitchApplication
    {
    	public partial class Application
    	{
    		partial void Application_Initialize()
    		{
    			// 6PM to 7AM
    			if(DateTime.Now.Hour >= 18 || DateTime.Now.Hour < 7)
    			{
    				Dispatchers.Main.BeginInvoke(() =>
    				{
    					System.Windows.MessageBox.Show("Cannot login at this time", "Invalid login time", MessageBoxButton.OK);
    					System.Windows.Application.Current.MainWindow.Close();
    				});
    			}
    		}
    	}
    }

    This will display a message box and then close the app.

    You could also implement this in the Application_LoggedIn partial is you want to control the hours by role.



    • Edited by Ian E Tuesday, July 12, 2016 4:59 AM
    • Marked as answer by Isahak Tuesday, July 12, 2016 5:29 AM
    Tuesday, July 12, 2016 4:34 AM

All replies

  • Hi Isahak,

    Why do you want to prevent users from logging after hours?

    Is logged in users get logged out after some time suitable for your situation? 

    Regards,

    Angie 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 11, 2016 6:05 AM
  • It's an operational requirement to disable access between certain hours...

    Isahak

    Monday, July 11, 2016 5:51 PM
  • Open a screen and then click Write Code -> _CanRun to create the Application.cs. Delete the _CanRun partial method.

    Implement an Application_Initialize partial method as follows to check a time range and close the app is not valid:

    using Microsoft.LightSwitch.Threading;
    using System;
    using System.Windows;
    
    namespace LightSwitchApplication
    {
    	public partial class Application
    	{
    		partial void Application_Initialize()
    		{
    			// 6PM to 7AM
    			if(DateTime.Now.Hour >= 18 || DateTime.Now.Hour < 7)
    			{
    				Dispatchers.Main.BeginInvoke(() =>
    				{
    					System.Windows.MessageBox.Show("Cannot login at this time", "Invalid login time", MessageBoxButton.OK);
    					System.Windows.Application.Current.MainWindow.Close();
    				});
    			}
    		}
    	}
    }

    This will display a message box and then close the app.

    You could also implement this in the Application_LoggedIn partial is you want to control the hours by role.



    • Edited by Ian E Tuesday, July 12, 2016 4:59 AM
    • Marked as answer by Isahak Tuesday, July 12, 2016 5:29 AM
    Tuesday, July 12, 2016 4:34 AM