0

I have created this login post method in my login controller, what it does is that it takes the email submitted (no password) and we run the email in the stored procedure to check if the user exists, if they do Set Authentication Cookie. Now I am looking to add on to this. Here is my current code:

WebServiceController service = new WebServiceController();

[HttpPost]
        public ActionResult Index(LoginClass model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {

                ModelState.AddModelError("", "The email provided is incorrect.");

                return View(model);
            }

            List<UserClass> user = service.loginUser(model.Email);

            if(user.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(model.Email, true);
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                    && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return Redirect(returnUrl);
                }

                return RedirectToAction("Index", "Home");
            }

            ModelState.AddModelError("", "The user name or password provided is incorrect.");

            return View(model);
        }

Now service.loginUser also returns a int value called divisionID and a user can have multiple divisionID, I would like the divisionID to be the users Role. My question is how would I go about implementing that?

user979331
  • 11,039
  • 73
  • 223
  • 418
  • 1
    You need to create `FormsAuthenticationTicket` by yourself. `UserData` is the place where you assign comma-separated role names. [Here](https://stackoverflow.com/a/45383932/296861) is the example. – Win Sep 13 '18 at 15:20
  • So do I not need to use FormsAuthentication.SetAuthCookie? – user979331 Sep 13 '18 at 15:29
  • Yo cannot use [FormsAuthentication.SetAuthCookie](https://learn.microsoft.com/en-us/dotnet/api/system.web.security.formsauthentication.setauthcookie?view=netframework-4.7.2) which doesn't take custom values. – Win Sep 13 '18 at 15:36

0 Answers0