コード例 #1
0
        public ActionResult Index(FormCollection objForm)
        {
            UserDataLayer objUserDataLayer = new UserDataLayer();
            bool          isChecked        = false;

            if (Request.Form["remember"] != null)
            {
                isChecked = true;
            }

            if (objUserDataLayer.AuthenticateUser(Request.Form["USer name"].ToString(), Request.Form["password"].ToString()))
            {
                FormsAuthentication.SetAuthCookie(Request.Form["USer name"].ToString(), isChecked);
                Session["IsPolice"] = objUserDataLayer.GetIsPoliceStatus(Request.Form["USer name"].ToString());
                if (Request.QueryString["returnUrl"] != "" && Request.QueryString["returnUrl"] != null)
                {
                    string sdf = Request.QueryString["returnUrl"];
                    return(Redirect(Request.QueryString["returnUrl"]));
                }
                FormsAuthentication.RedirectFromLoginPage(Request.Form["USer name"].ToString(), isChecked);
                ViewBag.UserName = System.Web.HttpContext.Current.User.Identity.Name;
                return(RedirectToAction("index", "Home"));
            }

            else
            {
                ViewBag.Status  = "unauthorized";
                ViewBag.Message = "Your crime details has been successfully sent to the department";
                return(View());
            }
        }
コード例 #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string        UserName         = System.Web.HttpContext.Current.User.Identity.Name;
            UserDataLayer objUserDataLayer = new UserDataLayer();
            bool          IsPolice         = objUserDataLayer.GetIsPoliceStatus(UserName);

            if (IsPolice)
            {
                base.OnActionExecuting(filterContext);
            }
            else
            {
                filterContext.Result = new RedirectResult(string.Format("/Error/Index"));
            }
        }