【问题标题】:ServiceStack.NET porting authentication from ASP.NETServiceStack.NET 从 ASP.NET 移植身份验证
【发布时间】:2013-10-23 07:44:55
【问题描述】:

在现有的 Silverlight 应用程序中,我将 WCF 服务替换为 ServiceStack 的服务...我成功地移植了所有服务并对其进行了测试..我还有最后一点要看...身份验证

目前,我使用基于 CustomMembershipProvider 的 Asp.NET 身份验证,该身份验证使用一些标准检查用户是否可以访问应用程序。

在我的每个服务方法中,我都有一些东西

public bool DoSomething(int idUser, string prefix)
    {
        if (!HttpContext.Current.User.Identity.IsAuthenticated) throw new SecurityExeption();

     //some computation

        return res;
    }

而且效果很好... 现在我试图在 ServiceStack 上实现同样的事情,我已经创建了我的 AuthProvider 如下

公共类 myAuthProvider : CredentialsAuthProvider { public override bool TryAuthenticate(IServiceBase authService, string userName, string password) { if (userName == "test" && 密码 == "test") 返回真;

        return false;
        //return base.TryAuthenticate(authService, userName, password);
    }

    public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
    {

        authService.SaveSession(session, SessionExpiry);
    }

}

并在一个示例项目上对其进行了测试(我保证在部署之前我会删除测试/测试!)

在我通过 SS 服务进行身份验证后,我尝试检查 HttpContext.Current.User.Identity.IsAuthenticated 是否有效,但我得到一个错误...我做错了什么还是 ServiceStack 不会在其上构建身份验证ASP.NET?我是否从错误的 AuthProvider 中脱颖而出?我希望通过 web.config 等将所有 asp.net feauter 持久化为滑动周期/会话超时

谢谢

【问题讨论】:

    标签: servicestack


    【解决方案1】:

    可能重复,但可能会有所不同,因为您使用的是 Silverlight。
    Use ASP.NET Membership in ServiceStack


    基于文档:

    “ServiceStack 的身份验证、缓存和会话提供程序是全新的、干净的、无依赖关系的可测试 API,不依赖并且没有 ASP.NET 现有的成员资格、缓存或会话提供程序模型。”

    https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization

    如果您使用的是服务堆栈 JsonServiceClient,则不会自动在您的请求中填写任何身份验证信息。此外,一旦您在 ServiceStack 上运行您的服务,您将选择退出任何 MS 内置身份验证方案。请参阅 Mythz 回答,了解如何与共享会话并行运行 ASP.NET 站点以及这是否适用于您的情况。

    我有一种预感,在您的自定义身份验证提供程序中,传递给 TryAuthenticate 的用户名和密码要么为 NULL,要么为空。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    相关资源
    最近更新 更多