示例#1
0
        void Application_Error(object sender, EventArgs e)
        {
            string ip = CommonStuff.GetLocalIPAddress(); // Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            Exception objErr = Server.GetLastError().GetBaseException();

            string objErrMgs = objErr.StackTrace;

            string err = "Error Date : " + DateTime.Now.ToString() + " , Error in: " + Request.Url.ToString() + " , Error Message:" + objErr.Message.ToString() + " ipaddress : " + ip;


            string path = HttpContext.Current.Server.MapPath("~/Logs/ErrorLog_GlobalErrors.txt");

            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path, true))
            {
                sw.WriteLine(err + objErrMgs);
                sw.WriteLine(objErr.StackTrace);
                sw.Close();
            }

            CommonStuff.SendEmail("*****@*****.**", "Error in DotNetIsEasy.com", objErr.Message.ToString() + "<br />IP: " + ip + "<br /><br />" + objErr.StackTrace);
            Server.ClearError();

            Response.Write(objErr.Message.ToString());
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Logger.log.Info("Login: emailId=" + model.Email + ",IP=" + CommonStuff.GetLocalIPAddress());
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

            UserMaster user = UserMaster.Login(model.Email, model.Password, con);

            string strp = UserMaster.EncryptString(model.Password);

            //UserLoginInfo user1 = new UserMaster();

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                ViewBag.ReturnUrl = returnUrl;
                return(View(model));
            }

            if (user.emailvalidation == 0)
            {
                ModelState.AddModelError("ValidateEmail", "Please Validate your Email First");
                ViewBag.ReturnUrl = returnUrl;
                return(View(model));
            }

            switch (user.user_status)
            {
            case UserStatus.Disabled:
                return(RedirectToLocal(returnUrl + "&Disabled"));

            case UserStatus.Suspended:
                return(RedirectToLocal(returnUrl + "&Suspended"));

            case UserStatus.LoggedIn:
                return(RedirectToLocal(returnUrl + "&LoggedIn"));

            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case UserStatus.Active:
            {
                if (strp == user.hashed_password)
                {
                    Session["uid"]         = user.uid;
                    Session["DisplayName"] = user.display_name;
                    Session["cid"]         = user.cid;
                    if (string.IsNullOrEmpty(returnUrl))
                    {
                        return(RedirectToAction("PostArtical", "Artical"));
                    }
                    else
                    {
                        return(Redirect(returnUrl));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(View(model));
                }
            }

            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }

            return(View(model));
        }