我试图在配置了SqlServer会话状态模式的应用程序中使用MvcSiteMapProvider。 但是,当我调用XmlSiteMapController类的RegisterRoutes方法时,我得到一个异常,如下所示:
public static void RegisterRoutes(RouteCollection routes) { // ... routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); // Add our route registration for MvcSiteMapProvider sitemaps MvcSiteMapProvider.Web.Mvc.XmlSiteMapController.RegisterRoutes(routes); }然后我得到一个例外说
在Assembly'System.Web中输入'System.Web.Routing.RouteValueDictionary',Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'未标记为可序列化。
这让我觉得MvcSiteMapProvider不支持SqlServer会话状态模式。 可以?
谢谢!
I am trying to use the MvcSiteMapProvider in an application that is configured with SqlServer session state mode. However, I get an exception the moment I call the RegisterRoutes method of XmlSiteMapController class, like this:
public static void RegisterRoutes(RouteCollection routes) { // ... routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); // Add our route registration for MvcSiteMapProvider sitemaps MvcSiteMapProvider.Web.Mvc.XmlSiteMapController.RegisterRoutes(routes); }Then I get an exception saying
Type 'System.Web.Routing.RouteValueDictionary' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
This makes me think MvcSiteMapProvider does not support SqlServer session state mode. Does it?
Thanks!
最满意答案
除非您已对其进行了自定义, MvcSiteMapProvider不会以任何方式与会话状态交互。 因此,它应该适用于任何会话状态模式(我没有使用SqlServer模式测试它,所以如果你继续遇到问题,我建议你打开一个关于它的新问题 )。 请参阅如何使MvcSiteMapProvider记住用户的位置,以获得有关如何在没有会话状态的情况下工作的说明。
发布的错误表明您的应用程序正在尝试序列化System.Web.Routing.RouteValueDictionary ,这不是MvcSiteMapProvider所做的事情。
另外,只要安装了MvcSiteMapProvider.MVC4 NuGet包,就不需要从MVC 4应用程序中显式调用XmlSiteMapController.RegisterRoutes 。 使用WebActivator自动调用此方法。 你有可能通过两次调用来解决问题。
Unless you have customized it, MvcSiteMapProvider does not interact with session state in any way. So, it should work with any mode of session state (I haven't tested it with SqlServer mode, so if you continue having issues I suggest you open a new issue about it). Please see How to Make MvcSiteMapProvider Remember a User's Position for an explanation about how it works without session state.
The error posted indicates your application is trying to serialize the System.Web.Routing.RouteValueDictionary, which is not something that MvcSiteMapProvider does.
On a side note, you don't need to call XmlSiteMapController.RegisterRoutes explicitly from an MVC 4 application as long as you have installed the MvcSiteMapProvider.MVC4 NuGet package. This method is called automatically using WebActivator. It is possible you might be having issues by calling it twice.
更多推荐
发布评论