【问题标题】:Code Behing update web.config mapping issue更新 web.config 映射问题的代码背后
【发布时间】:2010-11-29 15:35:24
【问题描述】:

我需要从后面的代码更新我的 web.config。这以前从来不是问题,但是我最近遇到了错误。错误说“无法映射路径'/'”。 注释掉的行是我尝试过的不同变体。

//Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(Server.MapPath("~"));
        //Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~");
        //Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(null);
        Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(".");
        // update pages theme
        RoleManagerSection section = (RoleManagerSection)myWebConfig.GetSection("system.web/roleManager");
        section.DefaultProvider = "SqlRoleManager";
        section.Providers.Clear();
        ProviderSettings providerSettings = new ProviderSettings();
        providerSettings.Name = "SqlRoleManager";
        providerSettings.Type = "System.Web.Security.SqlRoleProvider";
        providerSettings.Parameters.Clear();
        providerSettings.Parameters.Add("connectionStringName", "SimpleTickConnection");
        providerSettings.Parameters.Add("applicationName", "TheaterSales");
        section.Providers.Add(providerSettings);
        myWebConfig.Save();

【问题讨论】:

  • 我找到了错误的原因。将站点从我的本地 C: 驱动器移动到西方数字护照并运行应用程序后,错误开始了。下面这行代码没问题: Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");

标签: c# asp.net configuration asp.net-3.5


【解决方案1】:

我找到了错误的原因。将站点从我的本地 C: 驱动器移动到西方数字护照并运行应用程序后,错误开始了。下面这行代码没问题:

Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");

【讨论】:

    【解决方案2】:

    乍一看,尝试制作 WebConfigurationManager.OpenWebConfiguration(".");指向一个实际的配置文件,例如 web.config

    WebConfigurationManager.OpenWebConfiguration("web.config");

    如果需要,请确保还包括路径。

    【讨论】:

      【解决方案3】:

      文件路径“~/”表示Web 应用程序的根文件夹。 “~”和null对该方法没有任何意义; “。”表示当前(即bin)文件夹。

      【讨论】:

        【解决方案4】:

        当我从 Windows Vista 切换到 Windows 7 时发生了这种情况。Windows 7 的默认安全性导致了这种情况,因为 VS 没有打开文件的权限。只是我以管理员身份重新启动了 Visual Studio,它就可以工作,就这么简单。 我希望它可以帮助其他人。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-20
          • 2021-02-21
          • 1970-01-01
          • 2013-10-14
          • 2015-06-16
          • 1970-01-01
          相关资源
          最近更新 更多