public ActionResult Index(EmployeeDetail EmployeeDetail) { if (ModelState.IsValid) { string demoAddress = Sanitizer.GetSafeHtmlFragment(EmployeeDetail.Address); dbcon.EmployeeDetails.Add(EmployeeDetail); dbcon.SaveChanges(); return(RedirectToAction("DisplayEmployee", "Home")); } return(View(EmployeeDetail)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { var checkUserExists = dbcon.UserDetails.Where(p => p.UserName.ToLower() == model.UserName.ToLower()).FirstOrDefault(); if (checkUserExists == null) { UserDetail userDetail = new UserDetail(); userDetail.UserName = model.UserName; #pragma warning disable 618 var Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, "MD5"); #pragma warning restore 618 userDetail.Password = Password; userDetail.CreateDate = DateTime.Now; dbcon.UserDetails.Add(userDetail); dbcon.SaveChanges(); Session["Username"] = model.UserName; Session["UserID"] = userDetail.UserId; FormsAuthentication.SetAuthCookie(model.UserName, true); // Getting New Guid string guid = Convert.ToString(Guid.NewGuid()); //Storing new Guid in Session Session["AuthenticationToken"] = guid; //Adding Cookie in Browser Response.Cookies.Add(new HttpCookie("AuthenticationToken", guid)); return RedirectToAction("Index", "Home"); } else ModelState.AddModelError("", ErrorCodeToString(MembershipCreateStatus.DuplicateUserName)); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { string actionName = filterContext.ActionDescriptor.ActionName; string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var request = filterContext.HttpContext.Request; AuditTB objaudit = new AuditTB(); if (HttpContext.Current.Session["UserID"] == null) { objaudit.UserID = 0; } else { objaudit.UserID = Convert.ToInt32(HttpContext.Current.Session["UserID"]); } objaudit.UsersAuditID = 0; objaudit.SessionID = HttpContext.Current.Session.SessionID; objaudit.IPAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress; objaudit.PageAccessed = request.RawUrl; objaudit.LoggedInAt = DateTime.Now; if (actionName == "LogOff") { objaudit.LoggedOutAt = DateTime.Now; } objaudit.LoginStatus = "A"; objaudit.ControllerName = controllerName; objaudit.ActionName = actionName; AllSecurityDBEntities context = new AllSecurityDBEntities(); context.AuditTBs.Add(objaudit); context.SaveChanges(); //Finishes executing the Action as normal base.OnActionExecuting(filterContext); }