2013-05-13 218 views
1

我已經完成了一個mvc應用程序,我想在測試網站上發佈它。我設法用VS中的發佈命令發佈文件,但是當我訪問到我的應用的鏈接時,什麼都沒有。如何部署mvc應用程序

我用FTP發佈的網站,我檢查如果文件在主機上,他們是,但應用程序無法打開。 index.cshtml沒有顯示。我是否需要做一些額外的配置才能使其工作?

此外,我按照http://msdn.microsoft.com/en-us/library/dd410407(v=vs.90).aspx的步驟。


對web.release.config和web.debug.config有任何改變嗎?

這裏是我的web.config:

<configSections> 

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
</configSections> 
<connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=xxxxx Initial Catalog=xxxx; Persist Security Info=True; User ID=xxxxx; Password=xxxxx" providerName="System.Data.SqlClient" /> 
<add name="CDSEntities" connectionString="metadata=res://*/Models.CDS.csdl|res://*/Models.CDS.ssdl|res://*/Models.CDS.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxx;initial catalog=xxxxx;user id=xxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings> 

這裏是我web.release.config:

<system.web> 
<compilation xdt:Transform="RemoveAttributes(debug)" /> 
<!-- 
    In the example below, the "Replace" transform will replace the entire 
    <customErrors> section of your Web.config file. 
    Note that because there is only one customErrors section under the 
    <system.web> node, there is no need to use the "xdt:Locator" attribute. 

    <customErrors defaultRedirect="GenericError.htm" 
    mode="RemoteOnly" xdt:Transform="Replace"> 
    <error statusCode="500" redirect="InternalError.htm"/> 
    </customErrors> 
--> 

和我web.debug.config:

<system.web> 
<!-- 
    In the example below, the "Replace" transform will replace the entire 
    <customErrors> section of your Web.config file. 
    Note that because there is only one customErrors section under the 
    <system.web> node, there is no need to use the "xdt:Locator" attribute. 

    <customErrors defaultRedirect="GenericError.htm" 
    mode="RemoteOnly" xdt:Transform="Replace"> 
    <error statusCode="500" redirect="InternalError.htm"/> 
    </customErrors> 
--> 

回答

1

要回答我的問題:我所做的是以下幾點:

發佈使用VS,添加的服務器上使用FTP的文件。

然後添加以下到Web.config,因爲我得到了以下錯誤:在「/」應用

服務器錯誤。沒有爲擴展名「.cshtml」註冊的構建提供商。您可以在machine.config或web.config的部分中註冊一個。確保具有包含值'Web'或'All'的BuildProviderAppliesToAttribute屬性。

所以我增加了以下內容:

<compilation debug="true" targetFramework="4.0"> 

    <assemblies> 
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </assemblies> 
</compilation> 

在此之後在web.release.config我加入我的連接字符串從web.config。我舉一個例子,以使其更清晰:

<connectionStrings> 
    <add name="EAF" connectionString="Data Source=NTSQLT\S2K5TST;Initial Catalog=HR;User ID=EAFApp;Password=XXXX" providerName="System.Data.SqlClient" /> 
</connectionString> 

和web.release.config我加入XDT:轉換=「SetAttributes」 XDT:定位器=「匹配(名稱)」爲每個連接字符串。

<connectionStrings> 
    <add name="EAF" connectionString="Data Source=NTSQLP\S2K5TST;Initial Catalog=HR;User ID=EAFApp;Password=YYYY" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" /> 
</connectionStrings>