Copied to clipboard

Flag this post as spam?

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


  • stephencai 21 posts 131 karma points
    Apr 11, 2019 @ 04:31
    stephencai
    0

    Session Cookie always null

    I have created an API for login authentication purpose. The class extends UmbracoApiController, and it will calling another system endpoint to perform authentication and return user info. Everything is going right, however, there are always have an error after I use the bellows code to set/get the session cookies:

    HttpContext.Current.Session["token"]
    

    or

    UmbracoContext.HttpContext.Session["token"]
    

    HttpContext.Current.Session["token"] = "XXXXX"
    

    or

    UmbracoContext.HttpContext.Session["token"] = "XXXXX"
    

    ExceptionMessage: "Object reference not set to an instance of an object." ExceptionType: "System.NullReferenceException"

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 11, 2019 @ 06:42
    Dave Woestenborghs
    100

    Hi Stephen

    If I'm correct API controllers don't support session state out of the box.

    Here is some more information on how to enable it : https://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft