Skip to content

Instantly share code, notes, and snippets.

@jirolabo
Created November 16, 2018 13:32
Show Gist options
  • Save jirolabo/0cf6d8ca2f8e160f9c18152f2a25860c to your computer and use it in GitHub Desktop.
Save jirolabo/0cf6d8ca2f8e160f9c18152f2a25860c to your computer and use it in GitHub Desktop.
ASP.NET MVC SessionStateBehavior
public class CustomControllerFactory : DefaultControllerFactory
{
protected override SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, Type controllerType)
{
if (requestContext.HttpContext.Request.IsAjaxRequest())
{
// ajax の場合はセッションを読み取り専用にする
return SessionStateBehavior.ReadOnly;
}
return base.GetControllerSessionBehavior(requestContext, controllerType);
}
}
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
・・・
ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment