I currently have an IIS hosted application that I would like to switch over to use the self-hosted method.
But I\'m having difficulty accessing the session so I can
For ServiceStack 3, you can share request data via the HostContext.Instance.Items
Dictionary. For ServiceStack 4, you should use the HostContext.RequestContext.Items
Dictionary.
For example, add a request filter in your app host configuration to save the value:
// Put the session into the hostcontext.
RequestFilters.Add((req, res, requestDto) =>
{
HostContext.Instance.Items.Add("Session", req.GetSession());
});
Then in your authentication token class pull it back out:
public string GetCurrentAuthToken()
{
var session = HostContext.Instance.Items["Session"] as AuthUserSession;
if (session != null)
{
return session.UserName;
}
throw new Exception("No attached session found.");
}