Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kasper 14 posts 49 karma points
    Jan 29, 2023 @ 22:15
    Kasper
    0

    How to login using external table for storing Members

    Hi.

    I am trying to do FormsAuthentication login using an external table, where i store my Members. I do this because, need to ability create alot of members.. 1000-5000 every now an then.. And i dont want that type of member, along side the other type of member i need.

    Iam using webapi to send the username and password, and it seem to work fine, but the member is not logged in.

    This is what i have so far.

     [HttpPost]
        [Route("api/giftcardLogin")]
        public IHttpActionResult Login([FromBody] LoginRequest request)
        {
    
                try
                {
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                    1, // Ticket version
                    "SOMENAMEFROMEXTERNALSOURCE", // Username associated with ticket
                    DateTime.Now, // Date/time issued
                    DateTime.Now.AddMinutes(30), // Date/time to expire
                    true, // "true" for a persistent user cookie
                    "MEMBEREXTERNALROLE",// User-data, in this case the roles
                    FormsAuthentication.FormsCookiePath);// Path cookie valid for
    
                    string hash = FormsAuthentication.Encrypt(ticket);
                     HttpCookie cookie = new HttpCookie(
                        FormsAuthentication.FormsCookieName, // Name of auth cookie
                        hash); // Hashed ticket
                    if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
    
                    string[] roles = ticket.UserData.Split(',');
    
                    HttpContext.Current.User  = new System.Security.Principal.GenericPrincipal(HttpContext.Current.User.Identity, roles);
    
    
    
                    return Ok(ticket);
    
                }
                catch (Exception e)
                {
                    return BadRequest(e.Message);
                }
    
    
    
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies