Sergej Loch - 360 - Jan 25, 2015

Hello,

I’m using ServiceStack as self-hosted console application with Razor. Now I’m facing a problem with @Html.RenderAction("/dev","_Dev"). In this method I need the current session but I get always a new one and Request.Cookies is empty

    public class DevService : Service
    {
        public object Any(Dev request)
        {
            Debug.WriteLine(“current: " + IsAuthenticated+” - "+this.Request.Cookies);
            return new BaseContentViewModel();
        }
    }

I know I can workaround this with RequestContext or is there a better way?

Thanks

The existing request can’t be modified so a new Request is created for the new Action. I’ve just added a commit that will copy over the current request context when making a new request which will be available in next release.

In the meantime you can call the Service directly and render the returned viewModelin a partial, e.g:

var viewModel = base.ExecuteService<DevService>(s => s.Any(new Dev  { Id = 1 }));
@Html.Partial("_Dev", viewModel);

Sergej Loch:

Awesome! - Thank you