Asp.net mvc 如何部署mvc应用程序
我已经完成了一个mvc应用程序,我想在测试网站上发布它。我用VS中的publish命令发布了文件,但是当我访问应用程序的链接时,什么都没有 我使用FTP发布网站,我检查了文件是否在主机上,但应用程序没有打开。index.cshtml未显示。我需要做一些额外的配置,以使其工作吗 此外,我还遵循了中的步骤Asp.net mvc 如何部署mvc应用程序,asp.net-mvc,deployment,Asp.net Mvc,Deployment,我已经完成了一个mvc应用程序,我想在测试网站上发布它。我用VS中的publish命令发布了文件,但是当我访问应用程序的链接时,什么都没有 我使用FTP发布网站,我检查了文件是否在主机上,但应用程序没有打开。index.cshtml未显示。我需要做一些额外的配置,以使其工作吗 此外,我还遵循了中的步骤 是否需要对web.release.config和web.debug.config进行任何更改 这是我的web.config: <configSections> <sectio
是否需要对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="data source=xxxx;initial catalog=xxxxx;user id=xxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<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.release.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="data source=xxxx;initial catalog=xxxxx;user id=xxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<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>
-->
和my 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>
-->
回答我自己的问题:我所做的是: 使用VS发布,在服务器上使用FTP添加文件 然后,我将以下内容添加到web.config中,因为我遇到了以下错误: “/”应用程序中出现服务器错误。没有为扩展“.cshtml”注册生成提供程序。您可以在machine.config或web.config的部分中注册一个。确保is具有BuildProviderApplicationsToAttribute属性,该属性包含值“Web”或“All” 因此,我添加了以下内容:
<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:Transform=“SetAttributes”xdt:Locator=“Match(name)”
<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>
回答我自己的问题:我所做的是: 使用VS发布,在服务器上使用FTP添加文件 然后,我将以下内容添加到web.config中,因为我遇到了以下错误: “/”应用程序中出现服务器错误。没有为扩展“.cshtml”注册生成提供程序。您可以在machine.config或web.config的部分中注册一个。确保is具有BuildProviderApplicationsToAttribute属性,该属性包含值“Web”或“All” 因此,我添加了以下内容:
<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:Transform=“SetAttributes”xdt:Locator=“Match(name)”
<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>