Tôi đã ghi đè các CredentialsAuthProvider như vậy:Làm thế nào để chuyển hướng sau khi xác thực trong 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
}
tôi thực hiện một bài đơn giản để ~/auth/Credentials và trong khi các công trình thẩm định và phương pháp OnAuthenticated được gọi, làm thế nào để tôi thực sự chuyển hướng người dùng đến trang thích hợp dựa trên một vai trò hoặc một cái gì đó tương tự?
Tôi mệt mỏi để làm như sau trong phương pháp OnAuthenticated nhưng nó không có tác dụng mong muốn:
authService ("/ views/khách hàng");.
Cập nhật sử dụng Người khởi xướng Template (xem bình luận dưới đây):
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);
}
}
Và hình thức để POST:
<form method="POST" action="/auth/credentials">
<input name="UserName"/>
<input name="Password" type="password"/>
<input type="submit"/>
</form>
Đã hoạt động ... loại ... đây là hành vi: Tôi phải gửi biểu mẫu hai lần. Đây là thiết lập của tôi: tôi có Trang Nội dung default.cshtml trong thư mục gốc có biểu mẫu đăng nhập. Xem người chơi, sự khác biệt duy nhất tôi có thể thấy là, lần đầu tiên tôi tải trang, tôi không có cookie ss-id. Khi tôi gửi biểu mẫu, máy chủ sẽ gửi lại cho tôi default.cshtml. Nhưng lần này với một ss-id. Nếu tôi gửi lần thứ hai này, chuyển hướng bạn mô tả hoạt động. Whats với ss-id? – legion
Một lưu ý nữa, tôi nhận được ss-pid và tôi có Plugins.Add (new SessionFeature()); trong AppHost. – legion
'ss-id' được mô tả trong [Trang Wiki phiên dịch vụ của ServiceStack] (https://github.com/ServiceStack/ServiceStack/wiki/Sessions) – mythz