locked
Restrict User Access after certain time of day RRS feed

  • Question

  • We have a LightSwitch Web Application running publicly on internet. Normally users work from Office, certain management staff works from home as well.

    Since this is deployed on public computer, so anyone having credentials can access it from anywhere.

    Now our requirement is that if a user does NOT have certain permission then he/she should NOT access the application after for example 5:00 PM

    Thanks

    Friday, May 2, 2014 11:31 AM

Answers

  • Hello

    Are you using the HTML Client? If yes then my code below will be useless!!! If not then try this in the _CanRun event of the first(start) page of your application.

            partial void YOUR_PAGE_NAME_HERE_CanRun(ref bool result)
            {
                bool canRun = false;
                DateTime startTime = DateTime.Parse("09:00");
                DateTime endTime = DateTime.Parse("17:00");
                if (DateTime.Now.CompareTo(startTime) > 0 && DateTime.Now.CompareTo(endTime) < 0)
                {
                    canRun = true;
                }
    
                result = canRun;
            }


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, May 2, 2014 12:42 PM

All replies

  • Hello

    Are you using the HTML Client? If yes then my code below will be useless!!! If not then try this in the _CanRun event of the first(start) page of your application.

            partial void YOUR_PAGE_NAME_HERE_CanRun(ref bool result)
            {
                bool canRun = false;
                DateTime startTime = DateTime.Parse("09:00");
                DateTime endTime = DateTime.Parse("17:00");
                if (DateTime.Now.CompareTo(startTime) > 0 && DateTime.Now.CompareTo(endTime) < 0)
                {
                    canRun = true;
                }
    
                result = canRun;
            }


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, May 2, 2014 12:42 PM
  • Thanks Otis.

    No we are NOT using HTML Client, its SilverLight.

    So it means I have to do this on all my screens?

    Friday, May 2, 2014 1:28 PM
  • I would've thought that if it is applied to the first default screen set that the rest of the application wouldn't show. As I have not tested this or done it before I couldnt say for sure. But if you did have to do it in the _CanRun event for each screen you would be better off putting this into it's own function and then calling that for each page so you only had to edit the times in one place.

    HTH :)


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, May 2, 2014 3:08 PM
  • No I have to do it on each screen in this way. LightSwitch shows a link of the screen, if CanRun returns true, so if I disable for Default screen, only default screen link will disappear.

    Thanks

    Friday, May 2, 2014 3:20 PM
  • Glad I could help :)

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, May 2, 2014 3:24 PM