在 Asp.NET Web API 中访问 Session in Mono

Access Session in Asp.NET Web API in Mono

我在用户的会话对象中存储了一个复杂的权限列表。我在 AuthorizeAttribute 的自定义实现中访问它以管理对我的 REST API.

的访问

为了使其正常工作,我必须为 API 控制器启用 SessionState(默认情况下不会加载)。这成功了:

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");
}

它现在在开发期间在 VisualStudio 中工作正常,但是当我将它部署到单声道时,Session 对象再次为空。

知道如何强制 Mono 也为 API 控制器加载会话吗?

好的,好像不行。有一个 2012 年的错误:

SessionStateBehaviour in HttpContext is ignored

asp.net mono 中的会话还有其他错误:Memory leak in asp.net with sessions enabled

我改为 switched from the Session to a Dictionary for caching