public void ProcessRequest(HttpContext context) { try { var tRequestUri = HttpContext.Current.Request.Url; if (tRequestUri.PathAndQuery.ToLower().StartsWith("/wstest")) { ProcessRequest(new HttpContextWrapper(context)); return; } context.AcceptWebSocketRequest(async wsContext => { TheRequestData tRequestData = new TheRequestData { RequestUri = HttpContext.Current.Request.Url, HttpMethod = HttpContext.Current.Request.HttpMethod, UserAgent = HttpContext.Current.Request.UserAgent, ServerTags = TheCommonUtils.cdeNameValueToDirectory(HttpContext.Current.Request.ServerVariables), Header = TheCommonUtils.cdeNameValueToDirectory(HttpContext.Current.Request.Headers), ResponseMimeType = "cde/ws", ClientCert = HttpContext.Current.Request.ClientCertificate?.Count > 0 ? new System.Security.Cryptography.X509Certificates.X509Certificate2(HttpContext.Current.Request.ClientCertificate?.Certificate) : null //Verified that this works with no private key. Since C-DEngineCloud only works on Windows in IIS and MUST run as Administrator there is no linux check required here }; if (TheCommCore.MyHttpService != null && TheBaseAssets.MyServiceHostInfo.ClientCertificateUsage > 1) //If CDE requires a certificate, terminate all incoming requests before any processing { var err = TheCommCore.MyHttpService.ValidateCertificateRoot(tRequestData); if (TheBaseAssets.MyServiceHostInfo.DisableNMI && !string.IsNullOrEmpty(err)) { var terr = $"WebSocket Access with worng Client Certificate root - access is denied: {err}"; TheBaseAssets.MySYSLOG.WriteToLog(423, new TSM("TheCloudWSockets", terr, eMsgLevel.l1_Error)); return; } } await TheQueuedSenderRegistry.ProcessCloudRequest(wsContext.WebSocket, tRequestData); }); } catch (Exception ex) { TheBaseAssets.MySYSLOG.WriteToLog(423, new TSM("TheCloudWSockets", "Processing Error 500", ex.ToString())); context.Response.StatusCode = 500; context.Response.StatusDescription = ex.Message; context.Response.End(); } }
/// <summary> /// Processes the WebSockets request. /// </summary> /// <param name="context">The http context.</param> /// <param name="ws">The incoming WebSockets.</param> public async Task ProcessWSRequest(HttpContext context, WebSocket ws) { try { TheRequestData tRequestData = cdeASPNetCommon.CreateRequest(context); if (tRequestData == null) { return; } tRequestData.ResponseMimeType = "cde/ws"; await TheQueuedSenderRegistry.ProcessCloudRequest(ws, tRequestData); } catch (Exception ex) { TheBaseAssets.MySYSLOG.WriteToLog(423, new TSM("TheCloudWSockets", "Processing Error 500", ex.ToString())); context.Response.StatusCode = 500; } }