Reputation: 1679
How can I read the session info in ServiceStack?
public class HelloService : Service
{
public object Any(Hello request)
{
// How can I pull the session info i.e. UserId here?
}
}
Upvotes: 3
Views: 674
Reputation: 143409
You can get access to your typed custom session with:
public object Any(Hello request)
{
// How can I pull the session info i.e. UserId here?
var typedSessionUserId = base.SessionAs<MySession>().UserAuthId;
}
If you don't have a custom session then you can access the built-in AuthUserSession:
var typedSessionUserId = base.SessionAs<AuthUserSession>().UserAuthId;
Otherwise if you're using the dynamic session bag instead, you can access any custom variables you've added with:
var myUserId = base.Session["myUserId"];
Upvotes: 2