Asp.net mvc Web部署/发布正在添加未知的连接字符串?
以前发布我的web api应用程序工作得很好。今天,我将我的应用程序从“任意cpu”转换为x86。现在,当我发布它时,在web配置中添加一个连接字符串,这会导致我的应用程序失败。起初我想我可能不小心在web.config转换文件中添加了一些东西,但没有。这是我的转换文件:Asp.net mvc Web部署/发布正在添加未知的连接字符串?,asp.net-mvc,msdeploy,web-deployment,Asp.net Mvc,Msdeploy,Web Deployment,以前发布我的web api应用程序工作得很好。今天,我将我的应用程序从“任意cpu”转换为x86。现在,当我发布它时,在web配置中添加一个连接字符串,这会导致我的应用程序失败。起初我想我可能不小心在web.config转换文件中添加了一些东西,但没有。这是我的转换文件: <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the exampl
<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>
这是我的web配置文件:
<!--
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.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,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, 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 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.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,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="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>
如果您查看上面的内容,您将看到添加了一个连接字符串
经过一些研究,我发现您可以在发布期间添加连接字符串。我一直使用相同的配置文件发布,因此我多次删除该配置文件并创建了一个新配置文件,并确保取消选中该框以添加连接字符串:
MSDeploy
http://MyWebServer
我的网站/Go
假的
远程代理
约翰博布
假的
假的
正如你所看到的,里面有连接的东西,但我特别取消选中了“在运行时使用这个连接字符串(更新目标web配置)。如果我删除添加的连接字符串,我的网站就可以正常工作
有人知道发生了什么事吗
编辑:我想可能是我做错了什么,但今晚处理完之后,我认为这可能是一个bug。我决定回滚所有代码,看看是否可以重现这个问题。之前,在属性中的“包/发布Web”选项卡中,选中了“包/发布SQL选项卡中配置的所有数据库”。在“Package/Publish SQL”选项卡中,有一个连接字符串在“database entries”中定义,但为空。如果我让它保持原样,并试图发布一切完美的作品。如果我删除连接字符串并重新添加它,事情会再次变得一团糟。在上面的对话框中,如果“数据库”部分为空,则在创建配置文件时一切正常,但如果它有“远程连接字符串”框,则一切都不会正常工作。通过编辑XML将此项目属性添加到.csproj文件中:
<Project>
<PropertyGroup>
<AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
...
</PropertyGroup>
...
</Project>
. 对我有效的解决方案,尽管它更像是一种黑客行为,但它使用web部署转换来删除恶意连接字符串。请参见用户2395249回答:
在.pubxml文件中,由于某种原因添加了一些额外的连接字符串。
删除所有连接,它应该可以正常工作,默认的connectionstring仍然会被添加
我有一种预感,当我稍微修改发布信息时,它已经添加到了.pubxml中,但当我切换回常规发布设置时,它没有被删除
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String" />
<MSDeployParameterValue Include="$(DeployParameterPrefix)MyProject-Web.config Connection String" />
<MSDeployParameterValue Include="$(DeployParameterPrefix)MyProject_dev-Web.config Connection String" />
</ItemGroup>
<ItemGroup>
<_ConnectionStringsToInsert Include="MyProject" />
<_ConnectionStringsToInsert Include="Myproject_dev" />
</ItemGroup>
编辑project.csproj文件并添加以下内容:
<PropertyGroup>
<InsertAdditionalWebCofigConnectionStrings>false</InsertAdditionalWebCofigConnectionStrings>
假的
这对我有用 我也有同样的问题,发布向导会自动将连接字符串添加到已发布的web.config中,但我希望避免这种情况。您能否添加web.Release.config文件的内容,因为其中可能有一个转换正在添加连接字符串HI user127954,您解决了此问题吗?我也有同样的经历。为上下文事件添加虚拟连接字符串,尽管我明确告诉WebDeploy不要这样做。我使用的是defaultConnectionFactory,它根据用户登录的子域创建connectionstring。但是由于创建了伪connectionstring,defaultConnectionFactory变得无用。你找到解决办法了吗?@ToKa遗憾的是没有。这只是家里的一个小项目,不幸的是它已经不存在了。但几年前,我们刚刚开发了一款新的MVC5应用程序,遇到了同样的问题。它导致我们的站点失败,因为我们正在加密连接字符串。我们不得不做一些黑客来修复它,但它肯定仍然是一个问题。这似乎对我不起作用。即使有了这个属性,它仍然会每次都将连接字符串放入部署的web.config文件中。您能详细解释一下这个解决方案吗?
<PropertyGroup>
<InsertAdditionalWebCofigConnectionStrings>false</InsertAdditionalWebCofigConnectionStrings>