Example #1
0
        //On click send button Signalr connection open insert into database
        public void Send(string getCookie, string message, string storeTime)
        {
            //Get value from cookie
            getCookie = Models.AESCryptoStuff.CurrentInstance.AesDecrypt(HttpUtility.UrlDecode(Context.RequestCookies["uname"].Value));
            //Debug.WriteLine(storeCookie);
            //Insert into db
            db.ChatSendMessage(message, getCookie);
            foreach (var g in db.ChatGetTime())
            {
                storeTime = g;
            }
            //Censor Word
            Censors censorMessage = new Censors();
            string  storeCensored = censorMessage.CrapCensor(message);

            // Call the addNewMessageToPage method to update clients.
            Clients.All.addNewMessageToPage(getCookie, storeCensored, storeTime);
        }
Example #2
0
        public async Task <bool> TrySendAspnetExceptionMail(
            string to
            , string envName
            , string serviceIdentifier
            , HttpContext httpContext
            , Exception exception,
            Censors censors = null)
        {
            censors ??= new Censors();
            censors.headers ??= new string[] { "Authorization" };
            censors.cookies ??= new string[] {  };

            string body;

            //If something has disposed of the body stream by accident
            //(like disposing of a streamreader without leaveopen=true), this could throw.
            try
            {
                httpContext.Request.Body.Seek(0, SeekOrigin.Begin);
                using var bodyReader = new StreamReader(httpContext.Request.Body, leaveOpen: true);
                body = await bodyReader.ReadToEndAsync();

                if (body == "")
                {
                    body = "[Empty]";
                }
            }
            catch (Exception bodyReadException)
            {
                body = $"[Body could not be read]\n{bodyReadException}";
            }

            List <string> headers = new List <string>();

            foreach (KeyValuePair <string, StringValues> headerKvp in httpContext.Request.Headers)
            {
                if (headerKvp.Key == "Cookie")
                {
                    continue;
                }
                else if (censors.headers.Contains(headerKvp.Key))
                {
                    headers.Add(HttpUtility.HtmlEncode($"{headerKvp.Key}: [CENSORED]"));
                }
                else
                {
                    headers.Add(HttpUtility.HtmlEncode($"{headerKvp.Key}: {headerKvp.Value}"));
                }
            }

            List <string> cookies = new List <string>();

            foreach (KeyValuePair <string, string> cookie in httpContext.Request.Cookies)
            {
                cookies.Add(HttpUtility.HtmlEncode($"{cookie.Key}: {cookie.Value}"));
            }

            var cookieText = string.Join("</pre><pre>", cookies);

            if (cookieText == "")
            {
                cookieText = "[None]";
            }

            return(TrySendMail(
                       to
                       , $"[{envName}] {serviceIdentifier}: Internal Error"
                       , "<b>Url:</b><br><pre>" + HttpUtility.HtmlEncode(httpContext.Request.GetDisplayUrl())
                       + "</pre><br/><b>Method:</b><br/><pre>" + HttpUtility.HtmlEncode(httpContext.Request.Method)
                       + "</pre><br/><b>Client:</b><br/><pre>"
                       + HttpUtility.HtmlEncode(httpContext.Connection.RemoteIpAddress + ":" + httpContext.Connection.RemotePort)
                       + "</pre><br/><b>Headers:</b><br/><pre>" + string.Join("</pre><pre>", headers)
                       + "</pre><br/><b>Cookies:</b><br/><pre>" + cookieText
                       + "</pre><br/><b>Body:</b><br><pre>" + HttpUtility.HtmlEncode(body)
                       + "</pre><br/><b>Exception:</b><br><pre>" + HttpUtility.HtmlEncode(exception)
                       + "</pre>"));
        }