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
  • 58,060
  • 25
  • 98
  • 150
Manuel Valle
  • 297
  • 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,698
  • 8
  • 32
  • 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,118
  • 8
  • 16