Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAPI 2 attribute routing enable session state

We figured out how to enable session state with webapi Sample here

Now we have WebApi 2 attribute routing, so we no longer have route object to inject custom handler.

Is there any way of enabling session state with attribute routing?

like image 666
mamu Avatar asked Nov 03 '13 21:11

mamu


1 Answers

You need to add this to global.asax

protected void Application_PostAuthorizeRequest() 
{
    System.Web.HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
}

Then you could access the session through:

HttpContext.Current.Session
like image 128
Dalorzo Avatar answered Jan 15 '23 23:01

Dalorzo