How to logout authenticated user in ServiceStack?

2020-08-11 10:43发布

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 ?

2条回答
贪生不怕死
2楼-- · 2020-08-11 11:31

On ServiceStack v4 you will need this line instead.

client.Post(new Authenticate { provider = AuthenticateService.LogoutAction });
查看更多
戒情不戒烟
3楼-- · 2020-08-11 11:36

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" });
查看更多
登录 后发表回答