servicestack,Asp.net Mvc,Forms Authentication,servicestack" /> servicestack,Asp.net Mvc,Forms Authentication,servicestack" />

Asp.net mvc 跨应用程序进行表单身份验证的ServiceStack失败…为什么?

Asp.net mvc 跨应用程序进行表单身份验证的ServiceStack失败…为什么?,asp.net-mvc,forms-authentication,servicestack,Asp.net Mvc,Forms Authentication,servicestack,我有一个ServiceStack项目,在API.mydomain.com上运行API。同一解决方案中的管理项目位于admin.mydomain.com。管理员应用程序已经处理了登录/注销,但我想确保用户在我的api调用上经过身份验证(有时还检查权限)。我正在使用,以使auth cookie可用于我的api项目 以下是api项目中我的web.config身份验证标记: <authentication mode="Forms"> <forms protection="All"

我有一个ServiceStack项目,在API.mydomain.com上运行API。同一解决方案中的管理项目位于admin.mydomain.com。管理员应用程序已经处理了登录/注销,但我想确保用户在我的api调用上经过身份验证(有时还检查权限)。我正在使用,以使auth cookie可用于我的api项目

以下是api项目中我的web.config身份验证标记:

<authentication mode="Forms">
  <forms protection="All" loginUrl="home/denied" slidingExpiration="true" timeout="60" defaultUrl="home/denied" path="/" domain="mydomain.com" name=".myAuth"></forms>
</authentication>
在您的参考资料上,内容如下:

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

这意味着它是完全独立的,和ASP.NET现有的身份验证提供程序无关。i、 e.客户端需要显式调用
/auth
服务,以使用ServiceStack web服务进行身份验证


有关MVC网站的示例,请参阅示例演示项目,该网站在MVC控制器和ServiceStack web服务之间使用和共享ServiceStack的身份验证提供程序。

Ok,thx。这似乎有点令人沮丧……这使得向现有Asp.Net应用程序添加新服务层的故事变得更为复杂。如果我理解正确,我必须使用ServiceStack重新实现登录/身份验证。我经历了很多社交活动,但那真的不是我的情况。有没有办法制作一个适配器来使用Asp.Net会话用户?是的,你可以制作一个适配器,它只需要在内部调用ServiceStack AuthService,就像
[Authenticate]
属性对Basic+Digest所做的那样。Auth:谢谢,我来试一试。我没有按照你建议的方式来做。。。您认为这种方法有什么问题吗?我也喜欢这种方法(只需要一个过滤器来验证ASP.NET成员身份验证)-我将把它添加到TODO列表中,以便在未来的ServiceStack版本中获得类似的内容:)
public class AuthenticateAspNetAttribute : RequestFilterAttribute
{
    public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
    {
        SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

        using (var cache = req.GetCacheClient())
        {
            var sessionId = req.GetSessionId();
            var session = sessionId != null ? cache.GetSession(sessionId) : null;
            var originalRequest = (System.Web.HttpRequest) req.OriginalRequest;
            var identity = originalRequest.RequestContext.HttpContext.User.Identity;
            if (!identity.IsAuthenticated)
                AuthProvider.HandleFailedAuth(new BasicAuthProvider(), session, req, res);

        }
    }
}