Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ServiceStack从我的服务调用身份验证_C#_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack - Fatal编程技术网 servicestack,C#,servicestack" /> servicestack,C#,servicestack" />

C# ServiceStack从我的服务调用身份验证

C# ServiceStack从我的服务调用身份验证,c#,servicestack,C#,servicestack,我希望帮助用户从我的服务登录,因此,我不是直接发布到“/auth/basics”或“/auth/credentials”链接,而是从代码内部执行此操作: public class LoginService : Service { public LoginResponse Post(Login req) { var authService = ServiceStack.WebHost.Endpoints.AppHostBase.Instance.Container.Reso

我希望帮助用户从我的服务登录,因此,我不是直接发布到“/auth/basics”或“/auth/credentials”链接,而是从代码内部执行此操作:

public class LoginService : Service {
    public LoginResponse Post(Login req) {
        var authService = ServiceStack.WebHost.Endpoints.AppHostBase.Instance.Container.Resolve<AuthService>();
        authService.RequestContext = new HttpRequestContext(
            System.Web.HttpContext.Current.Request.ToRequest(),
            System.Web.HttpContext.Current.Response.ToResponse(), 
            null
        );
        authResponse = AuthService.Authenticate(
                           new Auth{ 
                               UserName = req.UserName, 
                               Password = req.Password,
                               RememberMe = true 
        });
        if(authResponse.UserName != null) {
            //sccessful
            //and does it automatically write session to cookies too? 
            //or do I need to write to session manually?
        }

    }
}
公共类登录服务:服务{
公共登录回复帖子(需要登录){
var authService=ServiceStack.WebHost.Endpoints.AppHostBase.Instance.Container.Resolve();
authService.RequestContext=新的HttpRequestContext(
System.Web.HttpContext.Current.Request.ToRequest(),
System.Web.HttpContext.Current.Response.ToResponse(),
无效的
);
authResponse=AuthService.Authenticate(
新身份验证{
UserName=req.UserName,
密码=请求密码,
RememberMe=true
});
如果(authResponse.UserName!=null){
//成功的
//它是否也会自动将会话写入cookies?
//或者我需要手动写入会话吗?
}
}
}

这就是我到目前为止发现的。这是正确的方法吗?我想和你确认一下。

你的方法有效吗?@J.Steen,嗯。奇怪的是,我半小时前才知道如何写这个,但它可以与FF、Chrome一起使用,第一次与IE一起使用,然后在IE中每隔一秒authResponse=null…不知道为什么。我想说,如果它有效,它是正确的。然而,由于您似乎有更多的问题,我建议您将您的问题编辑为与此相关,以使其更清楚、更具体。=)