c# - MVC 5 IIS;在 web.config 之前使用 machine.config

标签 c# asp.net-mvc iis web-config asp.net-membership

我正在尝试将 MVC5 网站部署到 IIS7 服务器。该网站使用 Asp.net 成员(member)资格。

当尝试连接到我的 SQlServer 时,网站正在尝试使用 machine.config 连接字符串“LocalSqlServer”。

但是我没有指定使用这个ConnectionString。我该如何更改此行为,使其使用 web.config 中给定的 connectionString 而不是 machine.cofnig。

  public ApplicationDbContext()
            : base("XXXXMembership", throwIfV1Schema: false)
        {
        }

网络配置:

<connectionStrings>
    <add name="XXXXMembership" connectionString="Data Source=xxxxxxxx;Initial Catalog=xxxxx;user id=xxxxx;password=xxxx;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

最佳答案

将此添加到您的 <connectionStrings> 的顶部节

<connectionStrings>
    <clear />
    <remove name="LocalSqlServer" />
    <add name="XXXXMembership" connectionString="Data Source=xxxxxxxx;Initial Catalog=xxxxx;user id=xxxxx;password=xxxx;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>

关于c# - MVC 5 IIS;在 web.config 之前使用 machine.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29776648/

相关文章:

c# - Visual Studio 2019 导致调试缓慢和内存使用率高

c# - 解析字符串以生成谓词

c# - 小写 Boolean.ToString() 值

c# - 使用 ADAL v3 使用 ClientID 对 Dynamics 365 进行身份验证

apache - ssl 证书适用于服务器还是主机名?

c# - 确定上传的文件是否为 MVC 上的图像(任何格式)

c# - 在 C# 中使用嵌入式资源图标作为应用程序图标

asp.net - 上下文菜单没有 "Add Scaffolding"和 "Add Controller"选项

asp.net - 带有 javascript :false in them being requested by clients of my website. 的 URL 为什么?

c# - "There is a duplicate ' system.web.extensions/脚本/scriptResourceHandler ' section defined"