1

I've a complex list of permissions stored in the user's session object. I'm accessing this in my custom implementation of the AuthorizeAttribute to manage access to my REST API.

In order to make it work, I had to enable the SessionState for API Controllers (by default it wouldn't be loaded). This did the trick:

protected void Application_PostAuthorizeRequest()
{
  if (IsWebApiRequest())
  {
    HttpContext.Current.SetSessionStateBehavior(
      System.Web.SessionState.SessionStateBehavior.Required);
  }
}

private static bool IsWebApiRequest()
{
  return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(@"~/api");
}

It works now fine in VisualStudio during development, but when I deploy it to mono the Session object is again null.

Any idea how I can force Mono to load the Sessions also for API Controller?

1 Answer 1

0

Ok, seems like it doesn't work. There is a bug from 2012:

SessionStateBehaviour in HttpContext is ignored

and there are also other bugs with sessions in asp.net mono: Memory leak in asp.net with sessions enabled

I've instead switched from the Session to a Dictionary for caching.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.