身份验证后,我覆盖了CredentialsAuthProvider像这样:如何重定向ServiceStack
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
//TODO: Auth the user and return if valid login
return true;
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
//User has been authenticated
//Find the user's role form the DB
if (roleA)
//GOTO mypage1
if (roleB)
//GOTO mypage2
}
我进行简单的后期到〜/认证/证书并且在认证工作和OnAuthenticated方法被调用,我该如何将用户重定向到基于角色或类似内容的相应页面?
我厌倦了做在OnAuthenticated方法如下,但它并没有收到预期的效果:
authService(“/视图/用户”)。
更新使用入门模板(见下文评论):
public class CustomCredentialsAuthProvider : CredentialsAuthProvider
{
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
return true;
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.ReferrerUrl = "http://www.msn.com";
base.OnAuthenticated(authService, session, tokens, authInfo);
}
}
而且形式POST:
<form method="POST" action="/auth/credentials">
<input name="UserName"/>
<input name="Password" type="password"/>
<input type="submit"/>
</form>
工作......有点......这是行为:我必须提交表单两次。 这是我的设置:我有一个default.cshtml内容页面在登录表单的根目录中。看着小提琴手,我能看到的唯一区别是,第一次加载页面时,我没有ss-id cookie。一旦我提交表单,服务器将我发送回default.cshtml。但是这次用ss-id。如果我第二次提交,你描述的重定向工作。什么与ss-id? – legion
还有一点需要注意,我确实得到了ss-pid,并且我有了Plugins.Add(new SessionFeature());在AppHost中。 – legion
'ss-id'在[ServiceStack的会话维基页面](https://github.com/ServiceStack/ServiceStack/wiki/Sessions)中有描述 – mythz