0

我正在使用Webmatrix進行身份驗證的ASP.Net MVC 4應用程序。我在我的web.config文件模式設置爲「SQLServer」的URL中的會話標識

<sessionState mode="SQLServer" cookieless="true" allowCustomSqlDatabase="true" 
    sqlConnectionString="Data Source=server;Initial Catalog=ASPState;Persist 
          Security Info=True;User ID=user;Password=password" 
    timeout="2880" sqlCommandTimeout="10" /> 

我可以看到正在填充ASPState的數據庫以下,但我仍然獲得在URL中的會話ID。當我嘗試通過Chrome訪問它時,出現許多重定向錯誤。當我通過IE瀏覽器訪問它的作品,即使我看到它重定向(儘管會話ID是在URL中),但錯誤,當我嘗試用下面的錯誤登錄:

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

我還沒有做出任何定製到Webmatrix,這都是默認設置。我需要會話ID,以保持不在網址和使用數據庫像我有它在web.config文件中設置

+0

此消息告訴您,您嘗試添加無法序列化的會話類 - 例如Dictionary <>無法保存在會話或其他您可能不使用[序列化]類的列表上,關鍵詞。 – Aristos

回答

2

首先,嘗試將Cookieless設置爲false。其次,使用ASPState時,allowCustomSqlDatabase應設置爲false,並且不要在連接字符串中指定Initial Catalog。 SQLState會自動在後臺執行。第四,我不知道你試圖序列化的是什麼,但是你應該把[Serializable]屬性放在你想要存儲在會話中的類的上面。

至於URL字符串中的會話ID,你使用的是IIS還是IIS Express? IIS使用一個小實用程序aspnet_filter.exe接受帶有會話ID的URL,並在內部將它重定向到適當的地址。同樣,它會將信息返回給您。網址通過裝飾過程再次出現。但是,我不確定IIS Express使用該實用程序。從某種意義上來說,在開發人員的機器上,你不會有太多的意義。

+0

+1,用於洞察aspnet_filter.exe。我一直在尋找IIS是否將會話ID作爲不同的URL處理。謝謝。 –