ASP.NET changing SessionStateBehviour

Viewed 126

When running multiple asp.net requests simultaneously downloading images can be very slow (several seconds). One way around this is to set the SessionStateBehaviour to "ReadOnly" at the start of the controller, using the code below. Is there a way to do this before the method is run so that I can decide on a per method basis if i want the session state to be Read only or not?

This is placed before the controller and does work, however i want more granuality.

[HttpContext.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.ReadOnly)]

I tried creating my own attribute using this code

public class SetSessionReadOnlyAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        filterContext.HttpContext.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.ReadOnly);
    }
}

I get the message: HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised.'

Does that mean there is no way to do this to each individual method?

0 Answers
Related