public LayIMMiddleware(RequestDelegate next, LayIMOptions options, IServiceProvider serviceProvider) { this.next = next; this.options = options; this.serviceProvider = serviceProvider; LayIMServiceLocator.SetServiceProvider(this.serviceProvider); }
/// <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); }
/// <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/)*.*$")); }
/// <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)); }
public static void SetOptions(LayIMOptions options) { layimOptions = options; }
public LayIMMiddleware(RequestDelegate next, LayIMOptions options) { this.next = next; this.options = options; }
/// <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")); }