Beispiel #1
0
 /// <summary>
 /// 是否通过代理https请求
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public static bool IsProxyHttpsRequest(ICompatibleRequest request)
 {
     // nginx反向代理
     if (request.GetHeader("X-Forwarded-Proto") == "https")
     {
         return(true);
     }
     // 兼容西部数码虚拟主机
     if (request.GetHeader("SSL-FLAG") == "SSL" || request.GetHeader("From-Https") == "on")
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        public static void SaveErrorLog(Exception exception)
        {
            lock (ErrorFilePath)
            {
                ICompatibleRequest req = HttpCtx.Request;
                var path         = req.GetPath();
                var query        = req.GetQueryString();
                var PathAndQuery = path + query;
                var referer      = req.GetHeader("Referer");;
                if (!File.Exists(ErrorFilePath))
                {
                    string dir = EnvUtil.GetBaseDirectory() + "tmp/logs";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    File.Create(ErrorFilePath).Close();
                }

                HttpCtx.Response.WriteAsync((File.Exists(ErrorFilePath).ToString()));
                using (FileStream fs = new FileStream(ErrorFilePath, FileMode.Append, FileAccess.Write))
                {
                    StreamWriter  sw = new StreamWriter(fs);
                    StringBuilder sb = new StringBuilder();

                    sb.Append("---------------------------------------------------------------------\r\n")
                    .Append("[错误]:IP:").Append(HttpCtx.RemoteAddress())
                    .Append("\t时间:").Append(DateTime.Now.ToString())
                    .Append("\r\n[信息]:").Append(exception.Message)
                    .Append("\r\n[路径]:").Append(PathAndQuery)
                    .Append("  -> 来源:").Append(referer)
                    .Append("\r\n[堆栈]:").Append(exception.StackTrace)
                    .Append("\r\n\r\n");

                    sw.Write(sb.ToString());

                    sw.Flush();
                    sw.Dispose();
                    fs.Dispose();
                }
            }
        }