Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928445

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:11:21+00:00 2026-05-27T11:11:21+00:00

I’m just getting started with ServiceStack and, as a test case, I am looking

  • 0

I’m just getting started with ServiceStack and, as a test case, I am looking to rework an existing service which is built using standard ASP.Net handlers. I’ve managed to get it all working as I want it but have certain aspects which make use of the ASP.Net Session object.

I’ve tried adding IRequiresSessionState into the service interface:

public class SessionTestService : RestServiceBase<SessionTest>, IRequiresSessionState {
    public override object OnPost(SessionTest request) {
        // Here I want to use System.Web.HttpContext.Current.Session
    }
}

The trouble is I can’t seem to get it to work as the Session object is always null.

I’ve done a lot of Googling and have puzzled over https://github.com/mythz/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Services/Secure.cs and similar but I can’t find any example code which does this (which surprises me). Can anyone explain why the above doesn’t work and advise what I need to do to get it working?

Note: Ultimately I’ll probably look to replace this with Redis or will try to remove any serverside session requirement, but I figured that I’d use the ASP.Net implementation for the time being, to get things working and to avoid reworking it more than is necessary at this point.

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:11:22+00:00Added an answer on May 27, 2026 at 11:11 am

    Using ServiceStack ISession

    ServiceStack has a new ISession interface backed by ICacheClient that lets you share same ISession between MVC Controllers, ASP.NET base pages and ServiceStack’s Web Services which share the same Cookie Id allowing you to freely share data between these web frameworks.

    Note: ISession is a clean implementation that completely by-passes the existing ASP.NET session with ServiceStack’s own components as described in ServiceStack’s MVC PowerPack and explained in detail in the Sessions wiki page.

    To easily make use of ServiceStack’s Session (Cache & JSON Serializer) have your Controllers inherit from ServiceStackController (in MVC) or PageBase (in ASP.NET)

    There is also new Authentication / Validation functionality added in ServiceStack which you can read about on the wiki:

    • Authentication and authorization
    • Validation

    Using ASP.NET Session

    Essentially ServiceStack is just a set of lightweight IHttpHandler’s running on either an ASP.NET or HttpListener host. If hosted in IIS/ASP.NET (most common) it works like a normal ASP.NET request.

    Nothing in ServiceStack accesses or affects the configured Caching and Session providers in the underlying ASP.NET application. If you want to enable it you would need to configure it as per normal in ASP.NET (i.e. outside of ServiceStack) see:

    http://msdn.microsoft.com/en-us/library/ms178581.aspx

    Once configured you can access the ASP.NET session inside a ServiceStack web service via the singleton:

    HttpContext.Current.Session
    

    Or alternatively via the underlying ASP.NET HttpRequest with:

    var req = (HttpRequest)base.RequestContext.Get<IHttpRequest>().OriginalRequest;
    var session = req.RequestContext.HttpContext.Session;
    

    Although because of the mandatory reliance on XML config and degraded performance by default, I prefer to shun the use of ASP.NET’s Session, instead opting to use the cleaner Cache Clients included with ServiceStack.

    Basically the way Sessions work (ASP.NET included) is a cookie containing a unique id is added to the Response uniquely identifying the browser session. This id points to a matching Dictionary/Collection on the server which represents the browsers’ Session.

    The IRequiresSession interface you link to doesn’t do anything by default, it simply is a way to signal to either a Custom Request Filter or base web service that this request needs to be authenticated (i.e. two places where you should put validation/authentication logic in ServiceStack).

    Here’s a Basic Auth implementation that looks to see if a web service is Secure and if so make sure they have authenticated.

    Here’s another authentication implementation that instead validates all services marked with an [Authenticate] attribute, and how to enable Authentication for your service by adding the Attribute on your Request DTO.

    New Authentication Model in ServiceStack

    The above implementation is apart of the multi-auth provider model included in the next version of ServiceStack. Here’s the reference example showing how to register and configure the new Auth model in your application.

    Authentication Strategies

    The new Auth model is entirely an opt-in convenience as you can simply not use it and implement similar behaviour yourself using Request Filters or in base classes (by overriding OnBeforeExecute). In fact the new Auth services are not actually built-into ServiceStack per-se. The entire implementation lives in the optional ServiceStack.ServiceInterfaces project and implemented using Custom Request Filters.

    Here are different Authentication strategies I’ve used over the years:

    • Mark services that need authentication with an [Attribute]. Likely the most idiomatic C# way, ideal when the session-id is passed via a Cookie.

    • Especially outside of a Web Context, sometimes using a more explicit IRequiresAuthentication interface is better as it provides strong-typed access to the User and SessionId required for Authentication.

    • You can just have a 1-liner to authenticate on each service that needs it – on an adhoc basis. A suitable approach when you have very few services requiring authentication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.