Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Normally you need to setup login controller and redirect to the page that you want if sucessfull like this:</p> <pre><code>[HttpPost] [AllowAnonymous] public ActionResult Login(LoginDto login) { string roles = "customers, Admin"; // this is the roles that you will add into roles authentications FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, userId, //user id DateTime.Now, DateTime.Now.AddMinutes(20), // expiry false, //do not remember roles, "/"); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); return RedirectToAction("Reserve", "MyController") } </code></pre> <p>and then you need to input that roles into principals when authentication happening (in Global.Asax file) :</p> <pre><code>protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User.Identity is FormsIdentity) { FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity; FormsAuthenticationTicket ticket = (id.Ticket); if (!string.IsNullOrEmpty(ticket.UserData)) { string userData = ticket.UserData; string[] roles = userData.Split(','); HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles); } } } } } </code></pre> <p>then you can use the authorization attribute in your method like your code:</p> <pre><code>[Authorize(Roles = "Customer")] [HttpPost] public ActionResult Reserve(My model model) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload