Reputation: 297
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?
Upvotes: 0
Views: 4112
Reputation: 1140
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);
}
Upvotes: 3
Reputation: 31
But instead of the following code in de webapiconfig
var route = config.Routes.MapHttpRoute(...
use the RoutTable class
var route = RouteTable.Routes.MapHttpRoute(...
Upvotes: 3