如何使用Asp.net MVC获取锁定/解锁事件

时间:2019-06-24 14:30:24

标签: c# asp.net-mvc-4

如何在Asp.net MVC应用程序中获取锁定/解锁时间

我尝试在控制台应用程序中使用该代码,并且可以正常工作:

static void Main(string[] args)
        {
            Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
            Console.ReadLine();
        }

        static void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason == SessionSwitchReason.SessionLock)
            {
                //I left my desk
                DateTime now = DateTime.Now;
                Console.WriteLine("I left my desk");
                Console.WriteLine("System lock Time:" + now);
            }
            else if (e.Reason == SessionSwitchReason.SessionUnlock)
            {
                //I returned to my desk
                DateTime now = DateTime.Now;
                Console.WriteLine("I returned to my desk");

                Console.WriteLine("System Unlock Time:" + now);
            }
        }

我在MVC应用程序中尝试了以下代码:

动作过滤器:

 public void OnActionExecuting(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason == SessionSwitchReason.SessionLock)
            {
                //I left my desk
                DateTime now = DateTime.Now;
                System.Diagnostics.Debug.WriteLine("System lock Time:" + now);
                Console.WriteLine("I left my desk");
                Console.WriteLine("System lock Time:" + now);

                AssignedOffersImplementation offerdetail_ = new AssignedOffersImplementation();
                //DateTime now = DateTime.Now;
                string Username = "prasanthkumar-reddy.sudha@chanel.com";


                Console.WriteLine(now);
                int locktime = offerdetail_.sp_updatelocktime(Username, now.ToString());



            }
            else if (e.Reason == SessionSwitchReason.SessionUnlock)
            {
                //I returned to my desk
                DateTime now = DateTime.Now;

                System.Diagnostics.Debug.WriteLine("System Unlock Time:" + now);
                Console.WriteLine("I returned to my desk");

                Console.WriteLine("System Unlock Time:" + now);


                AssignedOffersImplementation offerdetail_ = new AssignedOffersImplementation();
                //DateTime now = DateTime.Now;
                string Username = "prasanthkumar-reddy.sudha@chanel.com";


                Console.WriteLine(now);
                int locktime = offerdetail_.sp_updateunlocktime(Username, now.ToString());
            }
        }

预期:在MVC应用程序中获取锁定/解锁时间。

实际:无法在ASP.net MVC中获得锁定/解锁时间。 能够通过控制台应用程序访问。

0 个答案:

没有答案
相关问题