2013-05-13 130 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>