asp.net-mvc – Web Deploy/Publish正在添加一个未知的连接字符
以前发布我的网络api应用程序是完美的。今天我将应用从“任何cpu”转换为x86。现在,当我发布它添加一个连接字符串到Web配置,这导致我的应用程序失败。起初我虽然我可能不小心添加到web.config转换文件,但不是我没有。这是我的转换文件:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the example below,the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an attribute "name" that has a value of "MyDB". <connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <entityFramework xdt:Transform="Replace"> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework"> <parameters> <parameter value="Server=MyWebServer;Database=RunLog;Trusted_Connection=True; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> <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> --> </system.web> </configuration> 这是我的网络配置文件: <!-- For more information on how to configure your ASP.NET application,please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <configSections> <!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=5.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%Microsoft.NETFrameworkv4.0.30319aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%Microsoft.NETFramework64v4.0.30319aspnet_isapi.dll" preCondition="classicMode,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework"> <parameters> <parameter value="Data Source=(localdb)v11.0; Integrated Security=True; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> </configuration> 最后我发布这是我的web配置文件的样子: <?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application,PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <system.web> <compilation targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,EntityFramework"> <parameters> <parameter value="Server=MyWebServer;Database=RunLog;Trusted_Connection=True; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> <connectionStrings> <add name="RunLog" connectionString="RunLog_ConnectionString" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 如果你看上面你会看到一个连接字符串被添加。 经过一些研究,我发现你可以添加一个连接字符串durinig发布。那么我已经发布了相同的配置文件,所以我删除了多个配置文件,并创建了一个新的配置文件,并确保取消选中添加连接字符串的框: <?xml version="1.0" encoding="utf-8"?> <!-- This file is used by the publish/package process of your Web project. You can customize the behavior of this process by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. --> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>MSDeploy</WebPublishMethod> <SiteUrlToLaunchAfterPublish /> <MSDeployServiceURL>http://MyWebServer</MSDeployServiceURL> <DeployIisAppPath>My Web Site/Go</DeployIisAppPath> <RemoteSitePhysicalPath /> <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer> <MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod> <UserName>JohnBob</UserName> <_SavePWD>False</_SavePWD> <PublishDatabaseSettings> <Objects xmlns=""> <ObjectGroup Name="RunLog" Order="1" Enabled="False"> <Destination Path="" /> <Object Type="DbCodeFirst"> <Source Path="DBContext" DbContext="RunLog.DL.RunLogContext,RunLog.DL" Origin="Convention" /> </Object> </ObjectGroup> </Objects> </PublishDatabaseSettings> </PropertyGroup> <ItemGroup> <MSDeployParameterValue Include="$(DeployParameterPrefix)RunLog-Web.config Connection String"> <UpdateDestWebConfig>False</UpdateDestWebConfig> </MSDeployParameterValue> </ItemGroup> <ItemGroup> <_ConnectionStringsToInsert Include="RunLog" /> </ItemGroup> </Project> 正如你可以看到有连接的东西在那里,但我明确地取消选中“在运行时使用此连接字符串(更新目标Web配置)。如果我删除添加我的网站的连接字符串完美。 有人知道发生了什么吗? 编辑: 解决方法
通过编辑XML将此项目属性添加到.csproj文件:
<Project> <PropertyGroup> <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings> ... </PropertyGroup> ... </Project> 或者,使用如本related StackOverflow question中所述的Web发布管道目标文件。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET通过分布式Session提升性能
- asp.net-mvc – Razor:如何填写textarea?
- 如何加密ASP.NET MVC中的URL?
- asp.net – .resx vs数据库vs用于提供本地化/全球化的自定义
- 用于ASP.NET工作示例的Youtube API v3
- asp.net-mvc – Asp.Net Mvc 2 Checkbox在模型中总是假的
- asp.net-mvc – ASP.NET MVC路由冲突 – 输入变量的null值
- asp.net-web-api2 – ASP.NET 5(vNext)/ Web API / OAuth /
- asp.net-mvc – 如何在jqgrid中创建两个页脚行
- asp.net – LINQ to SQL执行时间比SSMS SQL长50倍
- asp.net-mvc – 如何在没有提示的情况下为Google
- asp.net – ScriptResource.axd和.Net 4
- asp.net – ConfigurationManager.AppSettings缓
- asp.net-mvc – 升级到.Net 4.5和osFamily 3后无
- asp.net-mvc-3 – Hz.Raw()的Razor替代品
- asp.net-mvc – 不一致的可访问性:DbContext中的
- ASP.NET内联编码:变量名不会被值替换
- 如何创建ASP.NET RecaptchaControl自定义模板
- asp.net – Global.asax没有为Release版本触发
- asp.net – SqlCacheDependency不起作用