How to logout authenticated user in ServiceStack?

2020-08-11 10:35发布

问题:

Apologize for the noob question. Just beginning to learn servicestack. I'm using a self-hosted console application with Razor for my view engine, the "RegistrationFeature" plugin for registrations and CredentialsAuthProvider for authentication via form post to allow users to login.

The SocialBootStrap application uses MVC 3 and does a "FormsAuthentication.SignOut()" to allow users to logout. Given that I'm using a self hosted application, I created a LogoutService that simply does a Request.RemoveSession() and that appears to work.

Is this the right way to log out a user's session ?

回答1:

There is an explicit logout service i.e. /auth/logout as part of the ServiceStack's Authentication support that you should use instead.

You can do a GET or POST to /auth/logout or if you're using C# client you can logout with:

client.Post(new Authenticate { provider = "logout" });


回答2:

On ServiceStack v4 you will need this line instead.

client.Post(new Authenticate { provider = AuthenticateService.LogoutAction });