How to rename default cookie names in servicestack

ServiceStack has default cookie names "ss-id" "ss-pid" and "ss-opt" defined in SessionFeature.cs

Is there a way to change the default names to something else?

The configuration code in HostConfig does not seem to reference it.

Would thank for the tips / pointers.

+4
source share
2 answers

As you noted in SessionFeature.cs , cookie names are defined as constnot configured by the user.

, cookie - . configure:

const string mySessionIdentifier = "mySessionId";

// Converts incoming requests with "mySessionId" cookie to "ss-id"
PreRequestFilters.Add((IRequest httpReq, IResponse httpRes) =>
{
    var cookie = httpReq.Cookies[mySessionIdentifier];
    if (cookie != null)
    {
        httpReq.Cookies.Remove(mySessionIdentifier);
        httpReq.Cookies.Add(ServiceStack.Keywords.SessionId, cookie);
    }
}


// Converts responses with outgoing cookie "ss-id" to "mySessionId"
GlobalResponseFilters.Add((IRequest httpReq, IResponse httpRes, object dto) => {
    var cookies = httpRes.CookiesAsDictionary();
    string cookie;
    if (cookies.TryGetValue(ServiceStack.Keywords.SessionId, out cookie))
    {
        httpRes.DeleteCookie(ServiceStack.Keywords.SessionId);
        httpRes.SetCookie(new Cookie(mySessionIdentifier, cookie));
    }
});

, .

+4

cookie - , , MVC domain.com api api.domain.com. servicestack ( ), ss-id .. . IE Edge, cookie , Chrome .

- MVC .com , apis . - IE, Chrome, MVC .

, MVC servicestack. domain.com www.domain.com, servicestack MVC.

.

+1

Source: https://habr.com/ru/post/1658454/


All Articles