标签: configsource

ASP.NET web.config:configSource与文件属性

web.configASP.NET应用程序的-file中,配置的某些部分(如appSettingsconnectionStrings)支持属性fileconfigSource.

使用file-attribute和configSource-attribute有什么区别?什么时候应该使用哪个属性,你可以同时使用它们吗?

<?xml version="1.0"?>
<configuration>
  <appSettings file="AppSettings.config">
  </appSettings>
  <connectionStrings configSource="ConnectionStrings.config">      
  </connectionStrings>
  <!-- ... -->
</configuration>
Run Code Online (Sandbox Code Playgroud)

asp.net configuration web-config configsource

179
推荐指数
1
解决办法
5万
查看次数

外部配置文件与elmah

我正在使用elmah(v1.1.11517.0)并尝试将配置移动到外部源.

我的配置目前看起来像这样:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
            <section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
        </sectionGroup>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    </configSections>
    <log4net configSource="Settings\RobDev\log4net.config" />
    <elmah configSource="Settings\RobDev\ELMAH.config" />
</configuration>
Run Code Online (Sandbox Code Playgroud)

log4net很高兴并且运行良好,但是对于elmah我得到了错误

Parser Error Message: The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config' or 'lock'.
Run Code Online (Sandbox Code Playgroud)

这是一种痛苦,elmah文件肯定存在,但有些事情并不快乐.

可能是什么导致了这个?

elmah web-config configsource

25
推荐指数
1
解决办法
4117
查看次数

在web.config下重写url的多个外部文件

之前我想将重定向保留在web.config之外,因为我有很多重写规则.我通过使用成功地做到了这一点

<rewrite>      
      <rules configSource="RewriteRules.config" />
</rewrite>
Run Code Online (Sandbox Code Playgroud)

现在问题是这个文件已经有很多规则了,我将为另一个指向相同基本代码的域使用另一组大量规则.所以我想在不同的文件上保留两个文件的规则,如: -

<rewrite>      
          <rules configSource="RewriteRules_a.config" />
          <rules configSource="RewriteRules_b.config" />
</rewrite>
Run Code Online (Sandbox Code Playgroud)

这是不允许的,任何人都可以建议我如何解决这种情况?请注意,这两个域将具有不同的规则,并且在此项目中可以更多地添加域.

任何建议将不胜感激......

asp.net mod-rewrite web-config url-rewriting configsource

7
推荐指数
1
解决办法
1677
查看次数

在同一解决方案中与多个项目共享连接字符串

我在同一个解决方案中有多个项目.我希望他们共享相同的connectionStrings,这样我就不必在多个地方更改它.

在我的网络配置中,我有

<connectionStrings  configSource="bin/connectionStrings.config" />
Run Code Online (Sandbox Code Playgroud)

然后我添加了一个文件作为我的"connectionsStrings.config"的链接,它位于解决方案级别.

我更改了属性,以便"复制到输出目录"是"始终复制"而"构建操作"是"内容"

但是我收到以下错误:

 The configSource attribute must be a relative physical path, so the '/' character is not allowed.
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题,任何帮助都会很棒.

干杯

connection-string config web-config configsource visual-studio-2012

6
推荐指数
1
解决办法
1823
查看次数

configSource 文件 'mycustom.config' 也用于父级,这是不允许的

如果您是在 VS2010 中开发的 ASP.NET 网站。(或在 VS2015 之前)

并且您的站点正在使用虚拟路径,例如“ http://localhost:12345/myvirpath

您可以通过在 Web.config 中使用 configSource 来自定义配置文件,如下所示:

<configuration>
    <configSections>
        <section name="MyConfig" type="mydomain.MyConfig_Model, mydomain" />
    </configSections>
    <ConfigRoot configSource="mycustom.config" />
    ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

您可以在开发中很好地进行测试,并且可以在Production IIS下的虚拟路径中顺利运行您的站点。

一切正常。


但是当您在 VS2015 中打开您的解决方案时。

由于 VS2015 不再提供“ASP.NET 开发服务器”。

您必须使用 IISEXPRESS 来开发和测试您的网站。

但是当您使用 IISEXPRESS 时,并在 Web 项目属性中将“项目 URL”设为“ http://localhost:12345/myvirpath ”。

按“F5”,你会得到错误信息:

configSource 文件“mycustom.config”也用于父级,这是不允许的。


原因是 IISEXPRESS 将创建 2 个站点,“ http://localhost:12345/ ”和“ http://localhost:12345/myvirpath

两个站点将指向相同的物理路径,这是不允许的。

所以会有那个错误信息。


我在谷歌上搜索了这个问题很多天,我找到了解决这个问题的最终方法,在这里分享一下。

解决办法是:

  1. 在 VS2015 中打开您的解决方案。

  2. 在您的 Web 项目属性中使项目 URL 为“ http://localhost:12345/myvirpath ”。

  3. “覆盖应用程序根 URL”复选框是不必要的。

  4. 打开您的 …

asp.net visual-studio-2010 virtual-directory configsource visual-studio-2015

6
推荐指数
0
解决办法
3618
查看次数

当Connectionstring configSource就位时,Visual Studio 2012添加具有上下文的控制器失败

当使用Errortring configSource到位时,使用VS 2012 + MVC4 + EF5尝试使用Context添加控制器失败:

"无法检索MvcTestApp.Models.DummyClass的元数据.无法打开configSource文件'connections.config'.

顺便说一句:路径是正确的,应用程序实际上正确运行.

Visual Studio 2012 EF5是否支持connectionStrings configSource在设计时位于单独的文件中?在开发过程中没办法!

感谢您的反馈意见.

frameworks entity configsource asp.net-mvc-4

5
推荐指数
1
解决办法
498
查看次数

使用configSource,并为核心部分更改restartOnExternalChanges

我想使用我的web配置部分的configSource属性来定义各种设置的外部文件.

特别是appSettings部分.这意味着我的配置文件具有以下条目:

<appSettings configSource="My.AppSettings.config" />
Run Code Online (Sandbox Code Playgroud)

但是,如果更新此文件,则不会自动选择设置,如果将设置手动包含在web.config中,则会出现这种情况.

进一步调查引导我进入restartOnExternalChanges属性.这显然可以与<section/>元素一起使用来定义configSource标识的外部文件是否可以触发重启.大!或者我想.

但是,在尝试定义appSettings部分并更改restartOnExternalChanges值时,我看到此处遇到相同的错误,因为appSettings部分是在machine.config中定义的 - 我无法更改的文件.

对于已经在更高级别定义的部分,是否有人知道是否可以使这两个设置一起工作?

.net configuration appsettings configsource

5
推荐指数
1
解决办法
3881
查看次数

为 bindingRedirects 定义单独的 configSource 并在 app.config 中引用它

我正在尝试定义一个单独的配置文件(比如redirect.config)。这个单独的配置文件包含 assemblyBindings 如下:

<?xml version="1.0" encoding="utf-8" ?>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="NServiceBus.Core" publicKeyToken="9fc386479f8a226c" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)

在 app.config 我想引用这个 redirect.config:

<runtime configSource="Redirects.config" />
Run Code Online (Sandbox Code Playgroud)

不幸的是,它根本不起作用。复制到输出目录设置为“始终复制”。有任何想法吗?提前致谢

.net c# app-config configsource

5
推荐指数
1
解决办法
507
查看次数