2014-10-17 52 views
0

我開發了一個使用VS2012 MVC 4(HotTowel SPA)的網絡應用程序 如果我通過Visual Studio運行它,它工作正常。但是當我將它部署到IIS服務器時,我收到一個異常。部署問題:(MVC4 HotTowel SPA)

我的服務器機器是Server 2008 R2和IIS 7.5版。所有的依賴關係都被安裝。

代碼部分導致錯誤:

在index.cshtml頁。如果檢查if(Session["User"] == null)然後載入視圖登錄。 (Login.cshtml) 如果session不爲空,則加載主視圖。 如果通過visual studio運行,一切正常。 如果我刪除會話檢查,則主頁將成功加載。 但我必須在回家之前檢查會話。但我得到以下異常:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Line 65:
Line 66: @if (Session["User"] == null) Line 67: { Line 68: @Html.Partial("Login")
}

回答

0

我找到了解決我的問題 就在這個模塊添加到您的web.config文件。

<configuration> 
... 
<system.webServer> 
... 
<modules> 
<remove name="Session" /> 
<add name="Session" type="System.Web.SessionState.SessionStateModule"/> 
... 
</modules> 
</system.webServer> 
</configuration> 

微軟在Template中添加了這個模塊是非常奇怪的。