本文介绍了项目部署时,事件在global.asax中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面你可以看到我在application_start中引发一个事件



AddHandler ChatService.OnContactsRequired,AddressOf ChatService_OnContactsRequired



并创建了一个方法



Private Sub ChatService_OnContactsRequired(ByVal obj As OnTtactsRequiredEventArgs)获取每个用户的联系人列表



这个代码在本地机器上工作正常但是,当我部署它并在服务器上发布时...它不工作,我们没有得到任何联系人列表





这是我的代码



..... global.asax .........

Below u can see i raise an event in application_start

AddHandler ChatService.OnContactsRequired, AddressOf ChatService_OnContactsRequired

and created a method

Private Sub ChatService_OnContactsRequired(ByVal obj As OnContactsRequiredEventArgs) to get contact list for every user

this code works fine in local machine but, when i deployed it and publish on server.. its not working and we didnt get any contactlist


here's my code

..... global.asax.........

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

If Boolean.Parse(ConfigurationManager.AppSettings("UseSqlProvider")) Then
Service.Instance.Storage = New SQLServerStorageProvider()
End If
ChatService.Start()
AddHandler ChatService.OnContactsRequired, AddressOf ChatService_OnContactsRequired
End Sub
 

Private Sub ChatService_OnContactsRequired(ByVal obj As OnContactsRequiredEventArgs)
Dim users = FakeDAL.GetAllContacts(Convert.ToString(obj.User.UserId))
 
For Each dbUser As DAL.User In users
Dim user = New Contact() With { _
.UserId = dbUser.UserId.ToString(), _
.Username = dbUser.DisplayName, _
.ImageUrl = dbUser.ImageUrl
}
obj.Contacts.Add(user)
Next
End Sub

推荐答案

这篇关于项目部署时,事件在global.asax中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 15:35