示例#1
0
 public async Task InvokeAsync(HttpContext context)
 {
     try
     {
         await _next(context);
     }
     catch (Exception ex)
     {
         Log4net.WriteError(ex.Message, ex);
         await new DB_Log().InsertError(await context.GetUserAsync(), ex, context);
         bool IsAjaxCall = context.Request.Headers["x-requested-with"] == "XMLHttpRequest";
         if (IsAjaxCall || context.Request.Path.StartsWithSegments("/api"))
         {
             context.Response.ContentType = "application/json";
             await context.Response.WriteAsync(new Basemessage()
             {
                 state = 500, message = "系统出错啦,相关异常信息已记录到日志,请联系管理员处理!",
             }.ToJson());
         }
         else
         {
             context.Response.Headers["Expires"] = " Mon, 26 Jul 1997 05:00:00 GMT";
             context.Response.Headers["Pragma"]  = "no-cache";
             context.Response.StatusCode         = (int)HttpStatusCode.InternalServerError;
             context.Response.Redirect("/Home/Error/500");
         }
     }
 }
示例#2
0
文件: FrmLogin.cs 项目: L-ZhiD/C-
        /// <summary>
        /// 登录事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtLoginId.CheckData(@"^\\d+$", "账号输入有误!") * txtLoginPwd.CheckNullOrEmpty() != 0)
            {
                SysAdmins sys = new SysAdmins()
                {
                    LoginId  = Convert.ToInt32(txtLoginId.Text.Trim()),
                    LoginPwd = txtLoginPwd.Text.Trim()
                };

                try
                {
                    sys = adminManager.AdminLogin(sys);
                    Log4net.WriteInfo($"账号[{sys.LoginId}]开始登录");
                    if (sys != null)
                    {
                        if (sys.AdminStatus == 1)
                        {
                            Log4net.WriteInfo($"[{sys.LoginId}]登录成功!");
                            Program.CurrentAdmin = sys;
                            this.DialogResult    = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            Log4net.WriteInfo($"[{sys.LoginId}]账号被禁用");
                            MessageBox.Show("当前管理员账号已被禁用!", "登录提示");
                        }
                    }
                    else
                    {
                        Log4net.WriteInfo($"[{sys.LoginId}]账号或密码错误登录失败");
                    }
                }
                catch (Exception ex)
                {
                    Log4net.WriteError($"[{sys.LoginId}]登录发生异常", ex);
                    return;
                }
            }
        }