如何在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中获得锁定/解锁时间。 能够通过控制台应用程序访问。