• 在线用户统计使用说明



    在线用户模块(OnlineUserBlock)使用说明
    • 初始化模块功能
      • 添加 OnlineUserBlock.dll 程序集引用。
      • 编写自身的 oluUserInfoProvider 。示例代码如下(采用Forms验证):
                                
        public class oluUserInfoProvider_Demo : oluUserInfoProvider
        {
        public override void AuthenticationSignout()
        {
        FormsAuthentication.SignOut();
        }

        public override oluUserInfo CreateMember(string IdentityName)
        {
        string nick=string.Format("会员:{0}",IdentityName);//应该去获取真正昵称
        oluUserInfo ui = new oluUserInfo(IdentityName, nick, false, null);
        return ui;
        }

        public override oluUserInfo CreateGuest()
        {
        oluUserInfo ui = new oluUserInfo("Guest", "路人甲", true, null);
        return ui;
        }
        }

        如果默认的oluUserInfo实体类不能满足要求,可以自行扩展;若不打算扩展,也可以将真正的会员信息实体类存到oluUserInfo的InnerUserData属性中。

      • 扩展oluUserInfo实体类的代码示例:
        public class oluUserInfoExtend : oluUserInfo
        {
        private string m_UserHostAddress = string.Empty;
        private string m_BrowserType = string.Empty;
        private string m_Platform = string.Empty;

        public oluUserInfoExtend(string userName, string nickName, bool anonymous, object userData)
        : base(userName,nickName,anonymous,userData)
        {
        m_UserHostAddress = HttpContext.Current.Request.UserHostAddress;
        m_BrowserType = HttpContext.Current.Request.Browser.Type;
        m_Platform = HttpContext.Current.Request.Browser.Platform;
        }

        public string UserHostAddress
        {
        get { return m_UserHostAddress; }
        }

        public string BrowserType
        {
        get { return m_BrowserType; }
        }

        public string Platform
        {
        get { return m_Platform; }
        }

        }
    • 配置web.cofing文件
      • 启用anonymousIdentification配置节点。在<system.web>节点中设置如下代码:
        <anonymousIdentification enabled="true" cookieless="UseDeviceProfile" cookieName=".oluDemoTicketName" cookieTimeout="90" />
      • 添加OnlineUserBlock的HttpModule模块。在<system.web>下的<httpModules>中添加:
        <add name="oluHttpModule" type="OnlineUserBlock.Components.oluHttpModule, OnlineUserBlock" />
      • 设置身份认证模式,本例中是Forms验证:
                            
        <authentication mode="Forms">
        <forms loginUrl="Login.aspx"
        protection="All"
        timeout="30"
        name=".oluDemoAuth"
        path="/"
        requireSSL="false"
        slidingExpiration="true"
        defaultUrl="online.aspx"
        cookieless="UseDeviceProfile"
        enableCrossAppRedirects="false" />
        </authentication>
    • 调整onlineuser.config配置文件
      • 在<providers>节点下添加第一步实现的oluUserInfoProvider。以下是本示例中的具体代码:
        <add name = "UserInfoProvider" type = "oluDemo.Extend.oluUserInfoProvider_Demo, OnlineUser.DemoSite" />
      • 设置核心的配置参数。一下是各参数的具体含义:
         
        TimeoutMember="10" 会员的超时时间(分钟)
        TimeoutRefresh="3" 客户端自动刷新的超时时间(分钟)
        TimeoutAnonymous="20" 访客的超时时间(分钟)
        EnableAutoRefresh="true" 是否启用客户端自动刷新
        IntervalScriptRefresh="60" 客户端自动刷新频率(秒)
        IntervalServerClearuser="300" 服务器端清理用户频率(秒)
        EnableMemberLoginSingleton="true" 是否启用会员单点登陆
        DefaultLanguage="zh-CN" 默认语言
      • 其他节点说明。

        <Languanges>节点下放置的是OnlineUserBlock中用到的本地化资源

    • 会员登陆和注销的注意事项
      • 登陆成功后需调用一下oluMonitor的MemberAppend(string IdentityName)方法。
        oluMonitor.MemberAppend(IdentityName); 
      • 注销时使用如下代码:
        oluMonitor.MemberSignout();
        针对本例而言,他真正调用的是oluUserInfoProvider_Demo中的AuthenticationSignout()方法,这里定义了具体的注销逻辑。
    • 程序中调用在线用户信息的方法
      • 通过oluMonitor.CurrUserInfo访问当前用户。
      • oluMonitor.GetAllUsers ()、oluMonitor.GetMembers()、oluMonitor.GetGuests()分别返回全部用户、会员、访客的集合,对应实体类 为oluUserInfo或其扩展类(取决于oluUserInfoProvider 的自身实现)。
    *注:模块的配置文件名称为【onlineuser.config】,可在web.config中的<appSettings>节点下设置其所处目录(默认在当前应用程序根目录下):
    <add key="oluCfgFolder" value="~/App_Data/" /><!--放在App_Data目录下-->


    演示站点
    http://olu.desktopit.net/
  • 相关阅读:
    Hive安装
    hbase安装
    Spring boot 出现的时间
    RESTful Web API 实践
    Java的进阶之道
    Spring boot 注解简单备忘
    使用 xshell 登录 Windows 的 linux 子系统
    Nginx 实用配置
    跟着大彬读源码
    跟着大彬读源码
  • 原文地址:https://www.cnblogs.com/yangjunwl/p/949324.html
Copyright © 2020-2023  润新知