8

servicestack のセッション機能プラグインに代わるものはありますか? 一部のシナリオでは、Cookie を使用して、サービスの実装で許可されたセッションと一致させることができません。リクエストの http ヘッダーでトークンを使用してセッションを解決する可能性はありますか? ブラウザが Cookie をブロックしている場合に推奨される解決策は何ですか?

4

2 に答える 2

4

@Guilherme Cardoso: In my current solution I am using a PreRequestFilters and the built-in session feature.

My workflow/workaround is the following:

When the user gets authorized I took the cookie and send it to the client by using an http header. Now the client can call services if the cookie is set in a http-header (Authorization) of the request.

To achieve this I redirect the faked authorization header to the cookie of the request using a PreRequestFilter. Now I am able to use the session feature. Feels like a hack but works for the moment ;-)

public class CookieRestoreFromAuthorizationHeaderPlugin : IPlugin
{
    public void Register(IAppHost appHost)
    {
        appHost.PreRequestFilters.Add((req, res) =>
            {
                var cookieValue = req.GetCookieValue("ss-id");

                if(!string.IsNullOrEmpty(cookieValue))
                    return;

                var authorizationHeader = req.Headers.Get("Authorization");

                if (!string.IsNullOrEmpty(authorizationHeader) && authorizationHeader.ToLower().StartsWith("basictoken "))
                {
                    var cookie = Encoding.UTF8.GetString(Convert.FromBase64String(authorizationHeader.Split(' ').Last()));

                    req.Cookies.Add("ss-id",new Cookie("ss-id",cookie));
                    req.Items.Add("ss-id",cookie);
                }
            });
    }
}
于 2013-06-24T15:26:05.960 に答える