2012-05-01 30 views
0

我試圖使用TempData的[]在MVC3控制器和我遇到了以下錯誤:TempData的[]使用在MVC3控制器犯錯瓦特/ SessionStateTempDataProvider類需要會話狀態啓用

The SessionStateTempDataProvider class requires session state to be enabled.

在webconfig(不是我的代碼或項目),而是......被設置以下

<modules runAllManagedModulesForAllRequests="true"> 
    <add name="Custom http Module" type="CustomHttpModule" /> 
</modules> 

其中CustomHttpModule:

public class CustomHttpModule: IHttpModule 

這是一個配置設置,我可以更改或可能定義在此CustomHttpModule類?

回答

2

確保如果您希望能夠從一個HTTP模塊訪問會話的模塊實現IRequiresSessionState標記接口:

public class CustomHttpModule: IHttpModule, IRequiresSessionState 
{ 
    ...  
} 

而且在web.config確保該session state啓用:

<sessionState mode="InProc" /> 

當然,您在此處指定的模式將取決於設置和要求。例如,如果您正在Web場中運行,將會話數據存儲在內存中可能會出錯,因爲Web場的每個節點都將存儲其自己的會話,並且不可能進行共享。在這種情況下,您可能需要考慮一些其他模式,這些模式使您能夠在服務器場的節點之間共享會話。

+0

太棒了......並且很好的瞭解分佈式洞察力。謝謝Darin! – JaJ