2015-05-11 22 views
0

我正在嘗試在配置了SqlServer會話狀態模式的應用程序中使用MvcSiteMapProvider。 不過,我得到一個異常的那一刻我稱之爲的RegisterRoutes方法XmlSiteMapController類的,就像這樣:MvcSiteMapProvider是否支持「Sql Server」會話狀態?

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); 
} 

然後我得到一個異常說

類型「的System.Web .Routing.RouteValueDictionary'in Assembly'System.Web,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'未標記爲可序列化。

這讓我覺得MvcSiteMapProvider不支持SqlServer會話狀態模式。可以?

謝謝!

回答

0

除非您定製了它,否則MvcSiteMapProvider不以任何方式與會話狀態交互。所以,它應該適用於任何會話狀態模式(我沒有用SqlServer模式測試過,所以如果你繼續有問題,我建議你打開一個new issue)。請參閱How to Make MvcSiteMapProvider Remember a User's Position瞭解如何在沒有會話狀態的情況下運行。

發佈的錯誤表明您的應用程序正試圖序列化System.Web.Routing.RouteValueDictionary,這不是MvcSiteMapProvider所做的。

在附註上,只要您已安裝MvcSiteMapProvider.MVC4 NuGet軟件包,則無需從MVC 4應用程序顯式調用XmlSiteMapController.RegisterRoutes。該方法使用WebActivator自動調用。通過調用它兩次可能會有問題。

+0

嗨!的確,它與MvcSiteMapProvider無關。對不起。它可能是另一個試圖在會話中保存它的組件。感謝您的關注。 – user4887773

0

MvcSiteMapProvider需要與狀態服務器交互,如果你想出於任何原因將節點放入會話狀態。我這樣做是爲了跟蹤我已經與節點關聯的對象,因爲MvcSiteMapProvider在每個新請求時都會忘記任何狀態信息。

如果您下載代碼,您可以將項目添加到解決方案中。

如果你做了更換和

更換public class[System.Serializable]\r\n\public class

還與[System.Serializable]\r\n\public abstract class

的替代public abstract class刪除屬性關閉JavaScriptSerializerAdapter類。

那麼它將可用於狀態服務器。