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?