今天在騰訊服務器上部署公司的項目,遇到了很多的問題,簡直可以用一波未平一波又起來形容。
記錄一下,怕自己忘記,順便也幫助跟我遇到同樣問題的人。
項目使用VS2010.MVC3.0開發,服務器的操作系統是Windows server 2008,下面我就講下部署的步驟。
1.安裝IIS
打開服務器管理器->角色->添加角色->勾選Web服務器(IIS),然后一直下一步,完成安裝即可,windows server 2008安裝的是IIS7
2.使用快捷鍵WIN+R,即打開運行窗口,然后輸入“inetmgr”,快速打開IIS
3.IIS左側有個樹列表,找到“網站”節點,右鍵新建網站,填寫網站名稱,綁定端口,還有項目的物理路徑。這里需要說一下,在創建網站的同時,你可以在應用程池列表中選擇一個來托管項目,
如果不選的話會自動生成一個與你網站名稱相同的應用程序池,如下圖所示。
應用程序池的.netframework版本根據你的項目而定,如果你的項目是用.netframework4.0開發的,用v2.0就會出錯。
當我滿心歡喜的輸入url,錯誤展現在我面前。下面是錯誤的內容。
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
當客戶端瀏覽時會出現這個錯誤,但這其實並不是真的錯誤,上面的意思主要是告訴我們如果程序出錯了,讓我們指定一個錯誤頁面,即使我加了<customErrors>,依舊報錯,要像發現真正的問題,還是得打開服務器上的IIS,
右側有個操作欄,瀏覽網站,看到了吧,點擊它,馬上拋出另一個錯誤,倍兒爽。
Server Error in '/' Application.
Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.
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.Web.HttpException: Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
這里原理我就不說了,只說解決方案,依舊Win+R,輸入"services.msc",打開windows服務列表,找到“ASP.NET 狀態服務”,打開這個這個服務並設置為自動。
ok 搞定!!
繼續在IIS瀏覽,打開以后,又你妹報錯了
未能加載文件或程序集“System.Web.Helpers, Version=1.0.0.0, Culture=neutral,
未能加載文件或程序集“System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一
解決方案:點我去下載MVC3,下載完安裝完,這個問題就解決了。
松口氣,瀏覽繼續報錯。。好吧IIS你贏了
譯器錯誤消息: CS0016: 未能寫入輸出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\2e9aca09\f067b5c4\App_Web_login.aspx.cdcab7d2.5bhornew.dll”--“拒絕訪問。
解決方案:這個圖比較多
C盤的Window目錄下找到TEMP文件夾,若沒有該文件夾,則Window目錄下自己創建一個TEMP文件夾。選擇TEMP文件夾點擊右鍵,然后選擇屬性。
長舒一口氣,繼續迎接新的報錯!!
錯誤信息 Server Error in ‘/’ Application. Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.
解決方案:這是因為沒有注冊asp.net4.0,WIN+R 輸入"cmd",進入命令行,輸入
C:/Windows/Microsoft.NET/Framework/v4.0.30319/aspnet_regiis.exe -i
回車運行,如果讀者的服務器是64系統,那么需要使用命令C:/Windows/Microsoft.NET/Framework64/v4.0.30319/aspnet_regiis.exe -i 來運行注冊iis。
在忐忑中,輸入url,終於出現了熟悉的頁面,總算可以下班回家了!!!!