Form Authentication and Active users in LightSwitch Web App

こ雲淡風輕ζ 提交于 2020-01-03 05:39:28

问题


Is there any way i can trace when user has Login (i.e. insert time of login in a log table) and how many users are currently active. I am using Form Authentication. I have search but i got stuff regarding custom login page. Is it possible to trace this using form authentication?

i have tried to insert a log into table on Application_LoggedIn

 Private Sub Application_LoggedIn()

        Dim A = Application.Current.CreateDataWorkspace.ApplicationData.Logtable.AddNew()
        A.name = User.Name
        A.time = DateTime.Now
        A.dates = DateTime.Now.Date
        A.Activity = "Login"
        Application.Current.CreateDataWorkspace.ApplicationData.SaveChanges()

    End Sub

But it does not seems to working. I checked in debug mode, the pointer passed but data is not inserted. I am not getting where i am doing wrong.

Is there any way i can call applicationdataservice public functions on client end?


回答1:


You're creating two separate data workspaces, once when you add the record, then another one when you save the changes. The two workspaces are not connected, so when you ask the second workspace to saves changes, there are none, because it's not aware of the record added in the first workspace.

Your code should be (I haven't tested this, but based on what I see wrong in your code):

Private Sub Application_LoggedIn()
    Using ws = Application.Current.CreateDataWorkspace
        Dim A = ws.ApplicationData.Logtable.AddNew()
        A.name = User.Name
        A.time = DateTime.Now
        A.dates = DateTime.Now.Date
        A.Activity = "Login"
        ws.ApplicationData.SaveChanges()
    End Using
End Sub


来源:https://stackoverflow.com/questions/16190939/form-authentication-and-active-users-in-lightswitch-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!