小编Rty*_*ype的帖子

ServiceStack:在自主应用程序中访问HttpRequest

我目前有一个IIS托管的应用程序,我想切换到使用自托管方法.

但我无法访问会话,因此我可以检索当前用户的用户名.

这是我在IIS下托管时使用的完美代码:

/// <summary>
/// A basic wrapper for the service stack session, to allow access to it lower down in the DAL layer without tying us to servicestack.
/// </summary>
public class ServiceStackAuthTokenService : IAuthTokenService
{
    /// <summary>
    /// GetCurrentAuthToken.
    /// </summary>
    /// <returns>A string representing the users auth name.</returns>
    public string GetCurrentAuthToken()
    {
        // Grab the current request.
        var req = HttpContext.Current.Request.ToRequest();
        var res = HttpContext.Current.Response.ToResponse();

        // Fetch the authentication service.
        var authService = EndpointHost.AppHost.TryResolve<AuthService>();
        authService.RequestContext = …
Run Code Online (Sandbox Code Playgroud)

authentication session servicestack

7
推荐指数
1
解决办法
2102
查看次数

标签 统计

authentication ×1

servicestack ×1

session ×1