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?

2
  • Does this help? Commented May 18, 2013 at 17:06
  • No, that links take me to a page where i can not find the code Commented May 18, 2013 at 17:25

2 Answers 2

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(...

Sign up to request clarification or add additional context in comments.

Comments

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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.