public LayIMMiddleware(RequestDelegate next, LayIMOptions options, IServiceProvider serviceProvider)
 {
     this.next            = next;
     this.options         = options;
     this.serviceProvider = serviceProvider;
     LayIMServiceLocator.SetServiceProvider(this.serviceProvider);
 }
Example #2
0
        /// <summary>
        /// 转换路由路径
        /// </summary>
        /// <param name="context"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string GetRoutePath(this HttpContext context, LayIMOptions options)
        {
            string path   = string.Empty;
            string prefix = options.ApiPrefix;

            if (!string.IsNullOrEmpty(prefix))
            {
                path = context.Request.Path.Value.Substring(prefix.Length);
            }
            else
            {
                path = context.Request.Path.Value;
            }
            return(path);
        }
Example #3
0
        /// <summary>
        /// 是否LayIM静态资源请求
        /// </summary>
        /// <param name="context"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static bool IsLayIMResourceRequest(this HttpContext context, LayIMOptions options)
        {
            string path = context.GetRoutePath(options);

            return(Regex.IsMatch(path, "^(js/|page/|css/|font/)*.*$"));
        }
Example #4
0
 /// <summary>
 /// 是否LayIM接口请求
 /// </summary>
 /// <param name="context"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static bool IsLayIMRequest(this HttpContext context, LayIMOptions options)
 {
     return(IsConfigPath(context.Request.Path.Value) || context.Request.Path.Value.StartsWith(options.ApiPrefix, StringComparison.CurrentCultureIgnoreCase));
 }
Example #5
0
 public static void SetOptions(LayIMOptions options)
 {
     layimOptions = options;
 }
Example #6
0
 public LayIMMiddleware(RequestDelegate next, LayIMOptions options)
 {
     this.next    = next;
     this.options = options;
 }
Example #7
0
        /// <summary>
        /// 是否LayIM静态资源请求
        /// </summary>
        /// <param name="context"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static bool IsLayIMResourceRequest(this HttpContext context, LayIMOptions options)
        {
            string path = context.ToRoutePath(options);

            return(path.StartsWith("/js") || path.StartsWith("/css"));
        }