asp.Net   发布时间:2022-04-05  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net-mvc – Web Deploy/Publish正在添加一个未知的连接字符串?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以前发布我的网络api应用程序是完美的。今天我将应用从“任何cpu”转换为x86。现在,当我发布它添加一个连接字符串到Web配置,这导致我的应用程序失败。起初我然我可能不小心添加到web.config转换文件,但不是我没有。这是我的转换文件:
<configuration xmlns:xdt="http://scheR_311_11845@as.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>

这是我的网络配置文件:@H_489_5@

<!--
  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,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_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配置文件的样子:@H_489_5@

<?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>

如果你看上面你会看到一个连接字符串被添加。@H_489_5@

经过一些研究,我发现你可以添加一个连接字符串durinig发布。那么我已经发布了相同的配置文件,所以我删除了多个配置文件,并创建了一个新的配置文件,并确保取消选中添加连接字符串的框:@H_489_5@

<?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://scheR_311_11845@as.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">
      <@R_197_9531@eDestWebConfig>false</@R_197_9531@eDestWebConfig>
    </MSDeployParameterValue>
  </ItemGroup>
  <ItemGroup>
    <_ConnectionStringsToInsert Include="RunLog" />
  </ItemGroup>
</Project>

正如你可以看到有连接的东西在那里,但我明确地取消选中“在运行时使用此连接字符串(更新目标Web配置)。如果我删除添加我的网站的连接字符串完美。@H_489_5@

有人知道发生了什么吗?@H_489_5@

编辑:
我以为也许我在做错事,但在今晚工作之后,我认为我是一个错误。我决定回滚我的所有代码,看看我是否可以重现问题。在“包/发布SQL”选项卡中,在“数据库条目”中定义了一个连接字符串,但是在“包/发布Web”选项卡中,“包/发布SQL”选项卡中配置的所有数据库已被选中它的空白,如果我按原样离开,并尝试发布所有功能完美,如果我删除连接字符串并重新添加它,事情会再次混乱在上面的对话框中,如果数据库部分是空白的,一切正常工作您创建一个配置文件,但如果它有远程连接字符串框,那么事情将无法正常工作@H_489_5@

解决方法

通过编辑XML将此项目属性添加到.csproj文件:
<Project>
  <PropertyGroup>

    <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>

    ...
  </PropertyGroup>
  ...
</Project>

或者,使用如本related StackOverflow question中所述的Web发布管道目标文件。@H_489_5@

大佬总结

以上是大佬教程为你收集整理的asp.net-mvc – Web Deploy/Publish正在添加一个未知的连接字符串?全部内容,希望文章能够帮你解决asp.net-mvc – Web Deploy/Publish正在添加一个未知的连接字符串?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。