Session is NULL when running ASP.NET MVC inside of ASP.NET

青春壹個敷衍的年華 提交于 2019-12-11 00:01:46

问题


If I create an ASP.NET Web Application project and then add an ASP.NET MVC 2 to it using the default routes defined like so

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { action = "Index", id = UrlParameter.Optional }
        );

The Session object is NULL when I try and access it in the action methods of the controllers. If I change my routes to this.

        routes.MapRoute(
            "Default", // Route name
            "{controller}.aspx/{action}/{id}", // URL with parameters
            new { action = "Index", id = UrlParameter.Optional }
        );

Everything works just fine. For whatever reason having the .aspx extension allows for session to be used, but the later doesn't. I'm using .NET 3.5 for everything.

Any ideas??? Thanks!


回答1:


The solution is to add runAllManagedModulesForAllRequests="true" to the configuration>system.webServer>modules tag in the web.config.



来源:https://stackoverflow.com/questions/3259632/session-is-null-when-running-asp-net-mvc-inside-of-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!