Created
November 16, 2018 13:32
-
-
Save jirolabo/0cf6d8ca2f8e160f9c18152f2a25860c to your computer and use it in GitHub Desktop.
ASP.NET MVC SessionStateBehavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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