Reputation: 60
I'm new to the ServiceStack world so I apologize if this question may seem like a waste of time.
I'm trying to leverage ServiceStack to power my mvc3 app.
I've stripped the app of its Membership Provider and I'm running all my authentication through ServiceStack built in auth. Much like the UserCase mvc example but instead of coupling SS auth with SimpleMembership Provider, I only use SS. All the mvc3 controllers extend ServiceStackController giving them easy access to all SS hooks.
The problem is, in my Razor views. I can't seem to inject SS into the mix. Because of this I have now way of knowing if my users are authenticated in my Views because Request.IsAuthenticated no longer works as it is not part of the SS framework. Is injecting SS AuthUserSession into asp Razor Views even possible?
Upvotes: 1
Views: 593
Reputation: 4816
There is a similar question here.
@inherits ViewPage
@{
var user = GetSession<AuthUserSession>();
}
<h1>@user.IsAuthenticated</h1>
Or
@{
var key = SessionFeature.GetSessionKey() ?? "";
var sess = AppHost.Resolve<ICacheClient>().Get<AuthUserSession>(key);
}
Should get you the user session and allow you to check if the user is authenticated.
Upvotes: 2