asp.net-mvcasp.net-mvc-5form-authenticationrole-manager

The new Asp.net Identity MVC 5 , can my old asp.net mvc 4 code still work


I have created a full module for managing Roles & Users inside asp.net mvc 4, for example the following action method will create a new Role:-

[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult CreateRole(MyRole mr)
        {

            if (Roles.RoleExists(mr.RoleName) || (String.IsNullOrEmpty(mr.RoleName)))
            {

                ModelState.AddModelError(string.Empty, "Role already there!!!");

                return View(mr);

            }
            else
            {

                Roles.CreateRole(mr.RoleName);

                return RedirectToAction("Index");
            }

        }

Now i am planning to upgrade my project to use asp.net MVC 5 , and also i will be working on a new asp.net mvc5 web project. and i checked the new membership classes used inside the asp.net mvc 5 , which seems to use a new RoleManager. so does this mean that my old code for managing Roles will no longer work on asp.net mvc 5 , since it uses a new membership module ? Thanks


Solution

  • It depend on Membership system which you are using. if you are using ASP.NET Membership, code still works and if you are going to use ASP.NET Identity, code no longer works.