0

I found solutions to add Session State for web api 4.0. But I have not found one for 4.5. Could some one point how to accomplish this?

tereško
  • 57,247
  • 24
  • 95
  • 149
Manuel Valle
  • 287
  • 8
  • 18

2 Answers2

3

Use this solutions:

But instead of the following code in de webapiconfig

var route = config.Routes.MapHttpRoute(...

use the RoutTable class

var route = RouteTable.Routes.MapHttpRoute(...

Thirumalai murugan
  • 5,354
  • 8
  • 30
  • 54
Michael
  • 31
  • 2
3

You can test the incoming request using RouteTable.Routes.GetRouteData to determine whether it is an Web API request:

    protected void Application_PostAuthorizeRequest()
    {
        // WebApi SessionState
        var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
        if (routeData != null && routeData.RouteHandler is HttpControllerRouteHandler)
            HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
    }
Stumblor
  • 1,108
  • 8
  • 16