Live Support, Chat, Upload Control and Rich Text Editor
Welcome to Support forums Sign in | Join | Help |Client Center
in Search

Global.asax

Last post 06-25-2009, 5:29 AM by pbwbart. 11 replies.
Sort Posts: Previous Next
  •  06-22-2009, 10:05 AM 53357

    Global.asax

     
    Must the integration of the cutechat be done in the global.asax or can I de the integration somewhere else on my site?
  •  06-22-2009, 12:49 PM 53363 in reply to 53357

    Re: Global.asax

    Hi,
     
    You can use custom http module to initialize the CuteChat.
     
    Regards,
    Terry.
  •  06-22-2009, 3:57 PM 53368 in reply to 53363

    Re: Global.asax

    Thanks for your Replay,
     
    Is it also possible to load this part in een http module?
    1. <script RunAt=server>   
    2.   
    3.     Public Overrides Sub Init()   
    4.         MyBase.Init()   
    5.            
    6.         If Not CuteChat.ChatSystem.HasStarted Then  
    7.             CuteChat.ChatProvider.Instance = New MyChatProvider()   
    8.             CuteChat.ChatSystem.Start(New CuteChat.AppSystem())   
    9.         End If  
    10.     End Sub  
    11.   
    12.   
    13. </script>  
    because I can only start the messenger once. The seccond user gets the message he/she already loged in.
    When the firs user logs out the second user can login but uses the username of the first user.
    The chatSystem will not start for a different instance of the application
     
     
  •  06-23-2009, 9:29 AM 53392 in reply to 53368

    Re: Global.asax

    Hi,
     
    If you get wrong username issue , I think your chat provider code is wrong.
     
    Regards,
    Terry
     
  •  06-23-2009, 12:45 PM 53426 in reply to 53392

    Re: Global.asax

    My code works now,
    I put my code completely in the global.asax and now (almost)everyting works
    users will be created into the cutechat module when they start it for the first time. Now it is also possible to start multiple instances.
    The only problem is that users can't add contacts
    so nobody has any friends
    When I'm trying to add another user I get this message
    "ADDCONTACT_CANTADDSELF"
    but actualy I want everyone to be in each contact list. so everybody is everybody's friend.
    But I can't figure out which dbtable contacts are stored.
    When I read some other posts here I get the feeling i'm missing a table "cutechat4_relation" or something
  •  06-23-2009, 9:32 PM 53434 in reply to 53426

    Re: Global.asax

    Hi,
     
    Can you post the ChatProvider code ?
     
    Regards,
    Terry
     
  •  06-24-2009, 1:25 AM 53444 in reply to 53434

    Re: Global.asax

    Hi Terry,
     
    My Complete code looks like this now:
    1. <%@ Application Codebehind="Global.asax.vb" Inherits="SiennEngine.Global_asax" Language="vb" %>   
    2. <%@ Import Namespace="System" %>   
    3. <%@ Import Namespace="System.Collections" %>   
    4. <%@ Import Namespace="System.ComponentModel" %>   
    5. <%@ Import Namespace="System.Web" %>   
    6. <%@ Import Namespace="System.Web.SessionState" %>   
    7. <%@ Import Namespace="System.Security.Principal" %>   
    8. <%@ Import Namespace="System.Data" %>   
    9. <%@ Import Namespace="System.Data.SqlClient" %>   
    10.   
    11. <%@ Import Namespace="CuteChat" %>   
    12.   
    13. <script runat="server" Language="vb">   
    14.        
    15.     Public Overloads Overrides Sub Init()   
    16.         MyBase.Init()   
    17.        
    18.         SyncLock GetType(CuteChat.ChatSystem)   
    19.             If Not CuteChat.ChatSystem.HasStarted Then  
    20.                 CuteChat.ChatProvider.Instance = New MyChatProvider()   
    21.                 CuteChat.ChatSystem.Start(New CuteChat.AppSystem())   
    22.             End If  
    23.         End SyncLock  
    24.     End Sub  
    25.        
    26.     Public Class MyChatProvider   
    27.         Inherits CuteChat.ChatProvider   
    28.         Dim pbw As New SiennEngine.PBW   
    29.         Dim Constring As String = pbw.get_constring()   
    30.         Dim Cid As String = pbw.get_cid_currentdomain()   
    31.      
    32.         Dim prefix As String = Cid & "U_"  
    33.         Dim userId as string = ""  
    34.            
    35.         Public Overloads Overrides Function GetConnectionString() As String  
    36.             Dim Retstring As String = Constring   
    37.             Return Retstring   
    38.         End Function  
    39.         Public Overloads Overrides Function FindUserLoginName(ByVal nickName As StringAs String  
    40.             try   
    41.                userId = httpcontext.current.request.Cookies("UserId").Value   
    42.             catch   
    43.             end try   
    44.             Dim Retstring As String = ""  
    45.             Dim Query As String = "Select UserName from " & prefix & "users where Id = " & UserId   
    46.             Dim Con As New SqlConnection(constring)   
    47.     
    48.             Dim Com As New SqlCommand(Query, Con)   
    49.             Try  
    50.                 Con.Open()   
    51.                 Dim Reader As SqlDataReader = Com.ExecuteReader()   
    52.                 While Reader.Read()   
    53.                     Retstring = reader(0)   
    54.                 End While  
    55.             Catch  
    56.             End Try  
    57.             Con.Close()   
    58.             Return Retstring   
    59.         End Function  
    60.         Public Overloads Overrides Function GetLogonIdentity() As AppChatIdentity   
    61.             'need to find the information of current user. Return null if user is anonymous.   
    62.             try   
    63.                userId = httpcontext.current.request.Cookies("UserId").Value   
    64.             catch   
    65.             end try   
    66.        
    67.             Dim loginname As String = ""  
    68.             Dim nickname As String = ""  
    69.             Dim Query As String = "Select UserName, NickName from " & prefix & "users where Id = " & UserId   
    70.             Dim Con As New SqlConnection(constring)   
    71.     
    72.             Dim Com As New SqlCommand(Query, Con)   
    73.             Try  
    74.                 Con.Open()   
    75.                 Dim Reader As SqlDataReader = Com.ExecuteReader()   
    76.                 While Reader.Read()   
    77.                     loginname = reader(0)   
    78.                     nickname = Reader(1)   
    79.                     If Nickname Is Nothing Or nickname = "" Then nickname = loginname   
    80.                 End While  
    81.             Catch  
    82.                 nickname = loginname   
    83.             End Try  
    84.             Con.Close()   
    85.   
    86.             Return New AppChatIdentity(nickname, False, ToUserId(loginname), HttpContext.Current.Request.UserHostAddress)   
    87.         End Function  
    88.         Public Overloads Overrides Function GetUserInfo(ByVal loginName As StringByRef nickName As StringByRef isAdmin As BooleanAs Boolean  
    89.             ' , if the loginName is invalid.   
    90.             'otherwise set the nickName and isAdmin , and return ture   
    91.             try   
    92.                userId = httpcontext.current.request.Cookies("UserId").Value   
    93.             catch   
    94.             end try   
    95.             Dim userType As Integer = 0   
    96.   
    97.             Dim Query As String = "Select NickName,UserType from " & prefix & "users where username='" & loginName & "'"  
    98.             Dim Con As New SqlConnection(constring)   
    99.     
    100.             Dim Com As New SqlCommand(Query, Con)   
    101.             Try  
    102.                 Con.Open()   
    103.                 Dim Reader As SqlDataReader = Com.ExecuteReader()   
    104.                 While Reader.Read()   
    105.                     UserType = reader(1)   
    106.                     nickname = Reader(0)   
    107.          
    108.          
    109.                     If Nickname Is Nothing Or nickname = "" Then nickname = loginname   
    110.                 End While  
    111.             Catch  
    112.                 nickname = loginname   
    113.             End Try  
    114.             Con.Close()   
    115.             If UserType = 1 Then  
    116.                 isAdmin = True  
    117.             Else  
    118.                 isAdmin = False  
    119.             End If  
    120.             Return True  
    121.         End Function  
    122.         Public Overloads Overrides Function ValidateUser(ByVal loginName As StringByVal password As StringAs Boolean  
    123.             'check the username/password .    
    124.             'if valid , set the cookie.   
    125.             Return True  
    126.         End Function  
    127.     End Class  
    128.        
    129. </script>  

    Regards
    pbwbart
  •  06-24-2009, 2:34 AM 53446 in reply to 53444

    Re: Global.asax

    Hi,
     
    The GetUserInfo is wrong.
     
    You should use the parameter 'loginName' , but not the httpcontext.
     
    And you use sql to get user info , you would better cache the result , because that function is called frequantly.
     
    Regards,
    Terry
  •  06-24-2009, 3:22 AM 53447 in reply to 53446

    Re: Global.asax

    My GetUserInfo is based on loginName
     
    1. Dim Query As String = "Select NickName,UserType from " & prefix & "users where username='" & loginName & "'"               
     
     The UserId is never used(only set).
     
    But that i actually want to know where contacts in a contactlist are stored so I can add them automaticly.
  •  06-24-2009, 5:04 AM 53454 in reply to 53447

    Re: Global.asax

    Cutechat,
     
    I think I'm seriously doing something wrong.
     
    I change my global.asax a little bit so the username is equal to the Id.
    Usernames can change, Id's don't.
    But now I'm discovering some problems.
    I can add Contacts some Times but cuteChat mixes my contacts.
    Sometimes the wrong contact will be added and sometimes I can't add them because the system thinks its me but it isn't
    and I can't add all contacts because they're already a contact. but it isn't, the system thinks this because contacts are mixed up.
     
    I'm using the default add contact button of the cutechat. So that can't be the problem.
     
    My discription above might be unclear but I don't know how to explain clearly.
     
    I have two users in the database(cutechat4_user) and the chatmodule thinks it's one.
    actualy I have five users now and cutechat thinks it's two but that doen't make any difference I think.
     
    Regards
     
    Bart
     
    Edit:
    This is my table export
    Since I only used the Id for logging in only User 1 and 3 can login.
    For some reason User 1 always ads bkock as contact no mather if he exists and what he types.
    User 2 always ads jrutten.
     
    User:1 bkock NULL NULL arr,S-1=10=User:bkock; InstantActivateTime:633814426528437500 NULL NULL
    User:3 jrutten NULL NULL arr,S-1=12=User:jrutten; InstantActivateTime:633814426917187500 NULL NULL
    User:admin admin NULL NULL NULL InstantActivateTime:633813609850468750 NULL NULL
    User:bkock bart NULL NULL NULL InstantActivateTime:633814399346406250 NULL NULL
    User:jrutten jrutten NULL NULL NULL InstantActivateTime:633813610605000000 NULL NULL
     
    When I delete a user from the dabase and I log in again(shut down IE an start again) the usersettings are the way they are before. So the session on the server will nog be killed. I removed synclock form the global.asas but this doesn't help.
     
    Might not unloading the messenger from the server is a part of the problem.
  •  06-24-2009, 9:39 AM 53462 in reply to 53454

    Re: Global.asax

    I still don't get it yet.
     
    It looks like a user can only add itself as a friend.
    User:1 bkock NULL NULL arr,S-1=10=User:bkock; InstantActivateTime:633814574025468750 NULL NULL
    User:3 jrutten NULL NULL arr,S-1=12=User:jrutten; InstantActivateTime:633814426917187500 NULL NULL
    User:4 mboerakker NULL NULL arr,S-1=15=User:mboerakker; InstantActivateTime:633814574831562500 NULL NULL
    User:7 admin NULL NULL arr,S-1=10=User:admin; InstantActivateTime:633814572798750000 NULL NULL
    User:admin admin NULL NULL NULL InstantActivateTime:633813609850468750 NULL NULL
    User:bkock bart NULL NULL NULL InstantActivateTime:633814399346406250 NULL NULL
    User:jrutten jrutten NULL NULL NULL InstantActivateTime:633813610605000000 NULL NULL
     
    Admin can only add admin as friend
    There was a user created "User:mboerakker" but I deleted it.
    Is there some kind of user grouping I use by accedent which I'm missing
  •  06-25-2009, 5:29 AM 53500 in reply to 53462

    Re: Global.asax

    Finally,
    I think I got it
     
    1. <%@ Application Codebehind="Global.asax.vb" Inherits="SiennEngine.Global_asax" Language="vb" %>   
    2. <%@ Import Namespace="System" %>   
    3. <%@ Import Namespace="System.Collections" %>   
    4. <%@ Import Namespace="System.ComponentModel" %>   
    5. <%@ Import Namespace="System.Web" %>   
    6. <%@ Import Namespace="System.Web.SessionState" %>   
    7. <%@ Import Namespace="System.Security.Principal" %>   
    8. <%@ Import Namespace="System.Data" %>   
    9. <%@ Import Namespace="System.Data.SqlClient" %>   
    10.   
    11. <%@ Import Namespace="CuteChat" %>   
    12.   
    13. <script runat="server" Language="vb">   
    14.        
    15.     Public Overloads Overrides Sub Init()   
    16.         MyBase.Init()   
    17.        
    18.         'SyncLock GetType(CuteChat.ChatSystem)   
    19.         If Not CuteChat.ChatSystem.HasStarted Then  
    20.             CuteChat.ChatProvider.Instance = New SiennChatProvider()   
    21.             CuteChat.ChatSystem.Start(New CuteChat.AppSystem())   
    22.         End If  
    23.         'End SyncLock   
    24.     End Sub  
    25.        
    26.     Public Class SiennChatProvider   
    27.         Inherits CuteChat.ChatProvider   
    28.         Dim pbw As New SiennEngine.PBW   
    29.         Dim Constring As String = pbw.get_constring()   
    30.         Dim Cid As String = pbw.get_cid_currentdomain()   
    31.      
    32.         Dim prefix As String = Cid & "U_"  
    33.         Dim userId As String = ""  
    34.            
    35.         Public Overloads Overrides Function GetConnectionString() As String  
    36.             Dim Retstring As String = Constring   
    37.             Return Retstring   
    38.         End Function  
    39.         'Public Overloads Overrides Function FindUserLoginName(ByVal nickName As String) As String   
    40.         '    Try   
    41.         '        userId = HttpContext.Current.Request.Cookies("UserId").Value   
    42.         '    Catch   
    43.         '    End Try   
    44.         'Dim Retstring As String = ""   
    45.         'Dim Query As String = "Select UserName from " & prefix & "users where Id = " & userId   
    46.         'Dim Con As New SqlConnection(Constring)   
    47.           
    48.         '       Dim Com As New SqlCommand(Query, Con)   
    49.         '          Try   
    50.         '             Con.Open()   
    51.         '    Dim Reader As SqlDataReader = Com.ExecuteReader()   
    52.         '         While Reader.Read()   
    53.         '              Retstring = Reader(0)   
    54.         '         End While   
    55.         '      Catch   
    56.         '     End Try   
    57.         '    Con.Close()   
    58.         '   Return Retstring   
    59.         'End Function   
    60.         Public Overloads Overrides Function GetLogonIdentity() As AppChatIdentity   
    61.             Dim user As System.Web.Security.MembershipUser = System.Web.Security.Membership.GetUser()   
    62.        
    63.             If user IsNot Nothing AndAlso user.IsApproved Then  
    64.                 Return New AppChatIdentity(user.UserName, False, ToUserId(user.UserName), HttpContext.Current.Request.UserHostAddress)   
    65.             End If  
    66.        
    67.             Return Nothing  
    68.         End Function  
    69.         'Public Overloads Overrides Function GetLogonIdentity() As AppChatIdentity   
    70.         'need to find the information of current user. Return null if user is anonymous.   
    71.         '           Try   
    72.         '               userId = HttpContext.Current.Request.Cookies("UserId").Value   
    73.         '           Catch   
    74.         '           End Try   
    75.         '      
    76.         '           Dim loginname As String = userId.ToString   
    77.         '           Dim Username As String = ""   
    78.         '           Dim nickname As String = ""   
    79.         '           Dim Query As String = "Select UserName, NickName from " & prefix & "users where Id = " & userId   
    80.         '           Dim Con As New SqlConnection(Constring)   
    81.           
    82.         '  Dim Com As New SqlCommand(Query, Con)   
    83.         '  Try   
    84.         '      Con.Open()   
    85.         '      Dim Reader As SqlDataReader = Com.ExecuteReader()   
    86.         '      While Reader.Read()   
    87.         '          Username = Reader(0)   
    88.         '          nickname = Reader(1)   
    89.         '          If nickname Is Nothing Or nickname = "" Then nickname = Username   
    90.         '      End While   
    91.         '  Catch   
    92.         '      nickname = Username   
    93.         '   End Try   
    94.         '    Con.Close()   
    95.         '    Return New AppChatIdentity(nickname, False, ToUserId(loginname), HttpContext.Current.Request.UserHostAddress)   
    96.         'End Function   
    97.         Public Overloads Overrides Function FindUserLoginName(ByVal nickName As StringAs String  
    98.             Dim user As System.Web.Security.MembershipUser = System.Web.Security.Membership.GetUser(nickName, False)   
    99.             If user IsNot Nothing AndAlso user.IsApproved Then  
    100.                 Return user.UserName   
    101.             End If  
    102.             Return Nothing  
    103.         End Function  
    104.         Public Overloads Overrides Function GetUserInfo(ByVal loginName As StringByRef nickName As StringByRef isAdmin As BooleanAs Boolean  
    105.             Dim user As System.Web.Security.MembershipUser = System.Web.Security.Membership.GetUser(loginName, False)   
    106.             If user IsNot Nothing AndAlso user.IsApproved Then  
    107.                 nickName = user.UserName   
    108.                 isAdmin = False  
    109.                 Return True  
    110.             End If  
    111.             Return False  
    112.         End Function  
    113.         'Public Overloads Overrides Function GetUserInfo(ByVal loginName As String, ByRef nickName As String, ByRef isAdmin As Boolean) As Boolean   
    114.         ' , if the loginName is invalid.   
    115.         'otherwise set the nickName and isAdmin , and return ture   
    116.         'Dim userType As Integer = 0   
    117.         'Dim UserName As String = ""   
    118.   
    119.         'Dim Query As String = "Select NickName,UserType,UserName from " & prefix & "users where Id='" & LoginName & "'"   
    120.         'Dim Con As New SqlConnection(Constring)   
    121.         '   
    122.         '      Dim Com As New SqlCommand(Query, Con)   
    123.         '         Try   
    124.         '            Con.Open()   
    125.         '   Dim Reader As SqlDataReader = Com.ExecuteReader()   
    126.         '          While Reader.Read()   
    127.         '             userType = Reader(1)   
    128.         '            nickName = Reader(0)   
    129.         '           UserName = Reader(2)   
    130.         '   
    131.         '             If nickName Is Nothing Or nickName = "" Then nickName = UserName   
    132.         '        End While   
    133.         '   Catch   
    134.         '      nickName = UserName   
    135.         ' End Try   
    136.         'Con.Close()   
    137.         '   If userType = 1 Then   
    138.         '       isAdmin = True   
    139.         '   Else   
    140.         '       isAdmin = False   
    141.         '   End If   
    142.         '  Return True   
    143.         'End Function   
    144.         Public Overloads Overrides Function ValidateUser(ByVal loginName As StringByVal password As StringAs Boolean  
    145.             'check the username/password .    
    146.             'if valid , set the cookie.   
    147.             System.Web.Security.FormsAuthentication.SetAuthCookie(loginName, False, HttpRuntime.AppDomainAppVirtualPath)   
    148.       
    149.             Return (True)   
    150.         End Function  
    151.     End Class  
    152.        
    153. </script>  
    now I have to figure out how to add contact automaticly
View as RSS news feed in XML
Powered by ASP.Net
Copyright 2003 - 2017 CuteSoft Components Inc.. All rights reserved.