DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

WebApi fails to write cookie

Sort:
You are not authorized to post a reply.





Growing Member





    I am building a custom login module to redirect the user to different pages based on the "type" of user. Users may be in certain roles or not a DNN user at all.

    I write a cookie to be read by a module on the target page denoting the type of user along with some other info.

    If the user is a non DNN user the cookie is written as expected.

    If the user is a DNN user, and logged in successfully, the cookie fails to write. Checking the Network tab in FF, the cookie is not in the response header.

    Login is done with:

        var loginStatus = UserLoginStatus.LOGIN_FAILURE;
        UserController.UserLogin(portalid, username, password, "", "", ipAddress, ref loginStatus, false);
        
    If I comment out UserController.UserLogin(... and return Login.SUCCESS, the cookie is written successfully. Checking the Network tab in FF, the cookie is in the response header.

    The response header is created using:

        HttpResponseMessage respMessage = new HttpResponseMessage();

        respMessage.Content = new ObjectContent(retVal, new JsonMediaTypeFormatter());
                
        Logger.Debug("=== Add Cookie   ======================================================");
        respMessage.Headers.AddCookies(new CookieHeaderValue[] { BuildCookie(cookiedata) });

        Logger.Debug("=== End Validate User   =================================================");

        return respMessage;


    Why does successful login in of a DNN user stop the cookie been written? Is there something else I need to do? Should I pass data between pages in some other way? Is IMC (Inter Module Communication) still a thing? In this instance IMC is not an option, for now, as the module on the target pages expects a cookie.

    Declan

    EDIT: As far as I recall, IMC is for modules on the same page.

     






    Veteran Member





      I don't recall having any issues writing cookies with similar code. We even do that with Hotcakes.
      You are not authorized to post a reply.

      These Forums are dedicated to the discussion of DNN Platform.

      For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

      1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
      2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
      3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
      4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
      5. No Flaming or Trolling.
      6. No Profanity, Racism, or Prejudice.
      7. Site Moderators have the final word on approving / removing a thread or post or comment.
      8. English language posting only, please.

      Would you like to help us?

      Awesome! Simply post in the forums using the link below and we'll get you started.

      Get Involved